6#include <QCoreApplication>
11#include <QRegularExpression>
12#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
13#include <QStringConverter>
18#include "libmythbase/mythconfig.h"
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")) {
330 QCoreApplication::postEvent(
this,
332 }
else if (! nc->
getArg(0).isEmpty()) {
333 result = QString(
"INVALID command '%1', try 'help' for more info")
346 LOG(VB_GENERAL, LOG_INFO,
LOC +
"Client Socket disconnected");
351 for (
auto * ncc : std::as_const(
m_clients))
353 if (ncc->getSocket()->state() == QTcpSocket::UnconnectedState)
372 LOG(VB_GENERAL, LOG_ERR,
LOC + QString(
"deleteClient(%1), unable to "
373 "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 "---------------------------------";
407 m_textStream(new QTextStream(s))
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")
622 return {
"Unable to change to main menu to start playback!"};
630 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback")
632 QString msg = QString(
"NETWORK_CONTROL STOP");
639 (
GetMythUI()->GetCurrentLocation().toLower() ==
"playback"))
640 std::this_thread::sleep_for(10ms);
643 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox")
649 while (!timer.hasExpired(10000) &&
650 (
GetMythUI()->GetCurrentLocation().toLower() !=
"playbackbox"))
651 std::this_thread::sleep_for(10ms);
655 std::this_thread::sleep_for(10ms);
658 if (
GetMythUI()->GetCurrentLocation().toLower() ==
"playbackbox")
664 QString msg = QString(
"NETWORK_CONTROL %1 PROGRAM %2 %3 %4")
667 QString::number(clientID));
678 std::this_thread::sleep_for(10ms);
683 result =
"ERROR: Timed out waiting for reply from player";
688 result = QString(
"ERROR: Unable to change to PlaybackBox from "
689 "%1, cannot play requested file.")
696 if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playmusic")
698 return QString(
"ERROR: You are in %1 mode and this command is "
699 "only for MythMusic")
710 message = QString(
"MUSIC_COMMAND %1 PLAY").arg(
hostname);
714 message = QString(
"MUSIC_COMMAND %1 PAUSE").arg(
hostname);
718 message = QString(
"MUSIC_COMMAND %1 STOP").arg(
hostname);
731 qApp->processEvents();
732 std::this_thread::sleep_for(10ms);
751 qApp->processEvents();
752 std::this_thread::sleep_for(10ms);
771 qApp->processEvents();
772 std::this_thread::sleep_for(10ms);
782 return {
"ERROR: Invalid 'play music' command"};
789 message = QString(
"MUSIC_COMMAND %1 SET_VOLUME %2")
794 message = QString(
"MUSIC_COMMAND %1 PLAY_TRACK %2")
799 message = QString(
"MUSIC_COMMAND %1 PLAY_URL %2")
804 message = QString(
"MUSIC_COMMAND %1 PLAY_FILE '%2'")
809 return {
"ERROR: Invalid 'play music' command"};
814 return {
"ERROR: Invalid 'play music' command"};
819 else if (
GetMythUI()->GetCurrentLocation().toLower() !=
"playback")
821 return QString(
"ERROR: You are in %1 mode and this command is only "
828 message = QString(
"NETWORK_CONTROL CHANID %1").arg(nc->
getArg(2));
830 return QString(
"ERROR: See 'help %1' for usage information")
835 static const QRegularExpression kChanID2RE {
"^[-\\.\\d_#]+$" };
838 return "ERROR: See 'help play' for usage information";
841 message =
"NETWORK_CONTROL CHANNEL UP";
843 message =
"NETWORK_CONTROL CHANNEL DOWN";
844 else if (nc->
getArg(2).contains(kChanID2RE))
845 message = QString(
"NETWORK_CONTROL CHANNEL %1").arg(nc->
getArg(2));
847 return QString(
"ERROR: See 'help %1' for usage information")
852 static const QRegularExpression kSeekTimeRE { R
"(^\d\d:\d\d:\d\d$)" };
855 return QString(
"ERROR: See 'help %1' for usage information")
860 message =
"NETWORK_CONTROL SEEK BEGINNING";
864 message =
"NETWORK_CONTROL SEEK FORWARD";
869 message =
"NETWORK_CONTROL SEEK BACKWARD";
871 else if (nc->
getArg(2).contains(kSeekTimeRE))
873#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
874 int hours = nc->
getArg(2).midRef(0, 2).toInt();
875 int minutes = nc->
getArg(2).midRef(3, 2).toInt();
876 int seconds = nc->
getArg(2).midRef(6, 2).toInt();
878 int hours = QStringView(nc->
getArg(2)).mid(0, 2).toInt();
879 int minutes = QStringView(nc->
getArg(2)).mid(3, 2).toInt();
880 int seconds = QStringView(nc->
getArg(2)).mid(6, 2).toInt();
882 message = QString(
"NETWORK_CONTROL SEEK POSITION %1")
883 .arg((hours * 3600) + (minutes * 60) + seconds);
887 return QString(
"ERROR: See 'help %1' for usage information")
893 static const QRegularExpression kSpeed1RE { R
"(^\-*\d+x$)" };
894 static const QRegularExpression kSpeed2RE { R
"(^\-*\d+\/\d+x$)" };
895 static const QRegularExpression kSpeed3RE { R
"(^\-*\d*\.\d+x$)" };
898 return QString(
"ERROR: See 'help %1' for usage information")
901 QString token2 = nc->
getArg(2).toLower();
902 if ((token2.contains(kSpeed1RE)) ||
903 (token2.contains(kSpeed2RE)) ||
904 (token2.contains(kSpeed3RE)))
905 message = QString(
"NETWORK_CONTROL SPEED %1").arg(token2);
907 message = QString(
"NETWORK_CONTROL SPEED normal");
909 message = QString(
"NETWORK_CONTROL SPEED 0x");
911 return QString(
"ERROR: See 'help %1' for usage information")
921 message = QString(
"NETWORK_CONTROL STOP");
925 static const QRegularExpression kVolumeRE {
"^\\d+%?$" };
928 (!nc->
getArg(2).toLower().contains(kVolumeRE)))
930 return QString(
"ERROR: See 'help %1' for usage information")
934 message = QString(
"NETWORK_CONTROL VOLUME %1")
935 .arg(nc->
getArg(2).toLower());
939 static const QRegularExpression kNumberRE {
"^\\d+$" };
942 message = QString(
"NETWORK_CONTROL SUBTITLES 0");
944 else if (!nc->
getArg(2).toLower().contains(kNumberRE))
946 return QString(
"ERROR: See 'help %1' for usage information")
951 message = QString(
"NETWORK_CONTROL SUBTITLES %1")
957 return QString(
"ERROR: See 'help %1' for usage information")
961 if (!message.isEmpty())
981 QString result =
"OK";
984 return QString(
"ERROR: See 'help %1' for usage information")
989 bool fullPath =
false;
990 bool mainStackOnly =
true;
993 fullPath = (nc->
getArg(2).toLower() ==
"true" || nc->
getArg(2) ==
"1");
995 mainStackOnly = (nc->
getArg(3).toLower() ==
"true" || nc->
getArg(3) ==
"1");
1001 if (location ==
"Playback")
1005 QString message = QString(
"NETWORK_CONTROL QUERY POSITION");
1009 QElapsedTimer timer;
1012 std::this_thread::sleep_for(10ms);
1017 result =
"ERROR: Timed out waiting for reply from player";
1034 return QString(
"VERSION: %1/%2 %3 %4 QT/%5 DBSchema/%6")
1037 MYTH_BINARY_VERSION,
1040 QString::number(dbSchema));
1050 std::chrono::seconds uptime = 0s;
1053 str = QString::number(uptime.count());
1055 str = QString(
"Could not determine uptime.");
1063 str = QString(
"getloadavg() failed");
1065 str = QString(
"%1 %2 %3").arg(loads[0]).arg(loads[1]).arg(loads[2]);
1076 if (
getMemStats(totalMB, freeMB, totalVM, freeVM))
1078 str = QString(
"%1 %2 %3 %4")
1079 .arg(totalMB).arg(freeMB).arg(totalVM).arg(freeVM);
1083 str = QString(
"Could not determine memory stats.");
1093 if (location !=
"Playback")
1097 QString message = QString(
"NETWORK_CONTROL QUERY VOLUME");
1101 QElapsedTimer timer;
1104 std::this_thread::sleep_for(10ms);
1109 str =
"ERROR: Timed out waiting for reply from player";
1130 nc->
getArg(3).toLower().toUInt());
1131 return QString(
"ERROR: See 'help %1' for usage information "
1132 "(parameters mismatch)").arg(nc->
getArg(0));
1136 return QString(
"ERROR: See 'help %1' for usage information")
1146 return QString(
"ERROR: See 'help %1' for usage information")
1149 if (nc->
getArg(1) ==
"verbose")
1152 return {
"ERROR: Missing filter name."};
1156 return QString(
"ERROR: Separate filters with commas with no "
1157 "space: playback,audio\r\n See 'help %1' for usage "
1158 "information").arg(nc->
getArg(0));
1162 QString result =
"OK";
1166 if (pva_result != 0 )
1170 result +=
" Previous filter: " + oldVerboseString +
"\r\n";
1173 LOG(VB_GENERAL, LOG_NOTICE,
1174 QString(
"Verbose mask changed, new level is: %1")
1180 return QString(
"ERROR: See 'help %1' for usage information")
1187 return "MythUIText";
1189 return "MythUITextEdit";
1191 return "MythUIGroup";
1193 return "MythUIButton";
1195 return "MythUICheckBox";
1197 return "MythUIShape";
1199 return "MythUIButtonList";
1201 return "MythUIImage";
1203 return "MythUISpinBox";
1204#if CONFIG_QTWEBENGINE
1206 return "MythUIWebBrowser";
1209 return "MythUIClock";
1211 return "MythUIStateType";
1213 return "MythUIProgressBar";
1215 return "MythUIButtonTree";
1217 return "MythUIScrollBar";
1219 return "MythUIVideo";
1221 return "MythUIGuideGrid";
1223 return "MythUIEditBar";
1231 return QString(
"ERROR: See 'help %1' for usage information")
1234 if (nc->
getArg(1) ==
"getthemeinfo")
1238 return QString(
"%1 - %2").arg(
themeName, themeDir);
1240 if (nc->
getArg(1) ==
"reload")
1246 if (nc->
getArg(1) ==
"showborders")
1252 if (nc->
getArg(1) ==
"shownames")
1258 if (nc->
getArg(1) ==
"getwidgetnames")
1263 path = nc->
getArg(2).split(
'/');
1275 return {
"ERROR: no top screen found!"};
1279 while (!path.isEmpty())
1281 QString childName = path.takeFirst();
1282 currType = currType->
GetChild(childName);
1284 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1290 for (
int i = 0; i < children->count(); i++)
1293 QString widgetName =
type->objectName();
1295 result += QString(
"%1 - %2\n\r").arg(widgetName, -20).arg(widgetType);
1300 if (nc->
getArg(1) ==
"getarea")
1303 return {
"ERROR: Missing widget name."};
1305 QString widgetName = nc->
getArg(2);
1306 QStringList path = widgetName.split(
'/');
1318 return {
"ERROR: no top screen found!"};
1322 while (path.count() > 1)
1324 QString childName = path.takeFirst();
1325 currType = currType->
GetChild(childName);
1327 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1332 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1334 int x =
type->GetFullArea().x();
1335 int y =
type->GetFullArea().y();
1336 int w =
type->GetFullArea().width();
1337 int h =
type->GetFullArea().height();
1338 return QString(
"The area of '%1' is x:%2, y:%3, w:%4, h:%5")
1339 .arg(widgetName).arg(x).arg(y).arg(w).arg(h);
1341 if (nc->
getArg(1) ==
"setarea")
1344 return {
"ERROR: Missing widget name."};
1347 return {
"ERROR: Missing X, Y, Width or Height."};
1349 QString widgetName = nc->
getArg(2);
1350 QStringList path = widgetName.split(
'/');
1351 QString x = nc->
getArg(3);
1352 QString y = nc->
getArg(4);
1353 QString w = nc->
getArg(5);
1354 QString h = nc->
getArg(6);
1367 return {
"ERROR: no top screen found!"};
1369 while (path.count() > 1)
1371 QString childName = path.takeFirst();
1372 currType = currType->
GetChild(childName);
1374 return QString(
"ERROR: Failed to find child '%1'").arg(childName);
1379 return QString(
"ERROR: widget '%1' not found!").arg(widgetName);
1383 return QString(
"Changed area of '%1' to x:%2, y:%3, w:%4, h:%5")
1384 .arg(widgetName, x, y, w, h);
1387 return QString(
"ERROR: See 'help %1' for usage information")
1413 QMap<QString, QString>::Iterator it;
1415 "Usage: jump JUMPPOINT\r\n"
1417 "Where JUMPPOINT is one of the following:\r\n";
1421 helpText += it.key().leftJustified(20,
' ',
true) +
" - " +
1428 "key LETTER - Send the letter key specified\r\n"
1429 "key NUMBER - Send the number key specified\r\n"
1430 "key CODE - Send one of the following key codes\r\n"
1433 QMap<QString, int>::Iterator it;
1442 helpText += it.key();
1449 "play volume NUMBER% - Change volume to given percentage value\r\n"
1450 "play channel up - Change channel Up\r\n"
1451 "play channel down - Change channel Down\r\n"
1452 "play channel NUMBER - Change to a specific channel number\r\n"
1453 "play chanid NUMBER - Change to a specific channel id (chanid)\r\n"
1454 "play file FILENAME - Play FILENAME (FILENAME may be a file or a myth:// URL)\r\n"
1455 "play program CHANID yyyy-MM-ddThh:mm:ss\r\n"
1456 " - Play program with chanid & starttime\r\n"
1457 "play program CHANID yyyy-MM-ddThh:mm:ss resume\r\n"
1458 " - Resume program with chanid & starttime\r\n"
1459 "play save preview\r\n"
1460 " - Save preview image from current position\r\n"
1461 "play save preview FILENAME\r\n"
1462 " - Save preview image to FILENAME\r\n"
1463 "play save preview FILENAME WxH\r\n"
1464 " - Save preview image of size WxH\r\n"
1465 "play seek beginning - Seek to the beginning of the recording\r\n"
1466 "play seek forward - Skip forward in the video\r\n"
1467 "play seek backward - Skip backwards in the video\r\n"
1468 "play seek HH:MM:SS - Seek to a specific position\r\n"
1469 "play speed pause - Pause playback\r\n"
1470 "play speed normal - Playback at normal speed\r\n"
1471 "play speed 1x - Playback at normal speed\r\n"
1472 "play speed SPEEDx - Playback where SPEED must be a decimal\r\n"
1473 "play speed 1/8x - Playback at 1/8x speed\r\n"
1474 "play speed 1/4x - Playback at 1/4x speed\r\n"
1475 "play speed 1/3x - Playback at 1/3x speed\r\n"
1476 "play speed 1/2x - Playback at 1/2x speed\r\n"
1477 "play stop - Stop playback\r\n"
1478 "play subtitles [#] - Switch on indicated subtitle tracks\r\n"
1479 "play music play - Resume playback (MythMusic)\r\n"
1480 "play music pause - Pause playback (MythMusic)\r\n"
1481 "play music stop - Stop Playback (MythMusic)\r\n"
1482 "play music setvolume N - Set volume to number (MythMusic)\r\n"
1483 "play music getvolume - Get current volume (MythMusic)\r\n"
1484 "play music getmeta - Get metadata for current track (MythMusic)\r\n"
1485 "play music getstatus - Get music player status playing/paused/stopped (MythMusic)\r\n"
1486 "play music file NAME - Play specified file (MythMusic)\r\n"
1487 "play music track N - Switch to specified track (MythMusic)\r\n"
1488 "play music url URL - Play specified URL (MythMusic)\r\n";
1493 "query location - Query current screen or location\r\n"
1494 "query volume - Query the current playback volume\r\n"
1495 "query recordings - List currently available recordings\r\n"
1496 "query recording CHANID STARTTIME\r\n"
1497 " - List info about the specified program\r\n"
1498 "query liveTV - List current TV schedule\r\n"
1499 "query liveTV CHANID - Query current program for specified channel\r\n"
1500 "query load - List 1/5/15 load averages\r\n"
1501 "query memstats - List free and total, physical and swap memory\r\n"
1502 "query time - Query current time on frontend\r\n"
1503 "query uptime - Query machine uptime\r\n"
1504 "query verbose - Get current VERBOSE mask\r\n"
1505 "query version - Query Frontend version details\r\n"
1506 "query channels - Query available channels\r\n"
1507 "query channels START LIMIT - Query available channels from START and limit results to LIMIT lines\r\n";
1512 "set verbose debug-mask - "
1513 "Change the VERBOSE mask to 'debug-mask'\r\n"
1514 " (i.e. 'set verbose playback,audio')\r\n"
1515 " use 'set verbose default' to revert\r\n"
1516 " back to the default level of\r\n";
1518 else if (
is_abbrev(
"screenshot", command))
1521 "screenshot - Takes a screenshot and saves it as screenshot.png\r\n"
1522 "screenshot WxH - Saves the screenshot as a WxH size image\r\n";
1524 else if (command ==
"exit")
1527 "exit - Terminates session\r\n\r\n";
1529 else if ((
is_abbrev(
"message", command)))
1532 "message - Displays a simple text message popup\r\n";
1534 else if ((
is_abbrev(
"notification", command)))
1537 "notification - Displays a simple text message notification\r\n";
1542 "theme getthemeinfo - Display the name and location of the current theme\r\n"
1543 "theme reload - Reload the theme\r\n"
1544 "theme showborders - Toggle showing widget borders\r\n"
1545 "theme shownames ON/OFF - Toggle showing widget names\r\n"
1546 "theme getwidgetnames PATH - Display the name and type of all the child widgets from PATH\r\n"
1547 "theme getarea WIDGETNAME - Get the area of widget WIDGET on the active screen\r\n"
1548 "theme setarea WIDGETNAME X Y W H - Change the area of widget WIDGET to X Y W H on the active screen\r\n";
1551 if (!helpText.isEmpty())
1554 if (!command.isEmpty())
1555 helpText += QString(
"Unknown command '%1'\r\n\r\n").arg(command);
1558 "Valid Commands:\r\n"
1559 "---------------\r\n"
1560 "jump - Jump to a specified location in Myth\r\n"
1561 "key - Send a keypress to the program\r\n"
1562 "play - Playback related commands\r\n"
1563 "query - Queries\r\n"
1565 "screenshot - Capture screenshot\r\n"
1566 "message - Display a simple text message\r\n"
1567 "notification - Display a simple text notification\r\n"
1568 "theme - Theme related commands\r\n"
1569 "exit - Exit Network Control\r\n"
1571 "Type 'help COMMANDNAME' for help on any specific command.\r\n";
1579 return QString(
"ERROR: See 'help %1' for usage information")
1582 QString message = nc->
getCommand().remove(0, 7).trimmed();
1585 qApp->postEvent(window, me);
1592 return QString(
"ERROR: See 'help %1' for usage information")
1595 QString message = nc->
getCommand().remove(0, 12).trimmed();
1603 QCoreApplication::postEvent(
1608 const QString &reply)
1617 static const QRegularExpression crlfRegEx(
"\r\n$");
1618 static const QRegularExpression crlfcrlfRegEx(
"\r\n.*\r\n");
1623 if (client && clientStream && client->state() == QTcpSocket::ConnectedState)
1625 *clientStream << reply;
1627 if ((!reply.contains(crlfRegEx)) ||
1628 ( reply.contains(crlfcrlfRegEx)))
1629 *clientStream <<
"\r\n" <<
m_prompt;
1631 clientStream->flush();
1640 auto *me =
dynamic_cast<MythEvent *
>(e);
1644 const QString& message = me->
Message();
1646 if (message.startsWith(
"MUSIC_CONTROL"))
1648 QStringList tokens = message.simplified().split(
" ");
1649 if ((tokens.size() >= 4) &&
1650 (tokens[1] ==
"ANSWER") &&
1654 for (
int i = 4; i < tokens.size(); i++)
1655 m_answer += QString(
" ") + tokens[i];
1660 else if (message.startsWith(
"NETWORK_CONTROL"))
1662 QStringList tokens = message.simplified().split(
" ");
1663 if ((tokens.size() >= 3) &&
1664 (tokens[1] ==
"ANSWER"))
1667 for (
int i = 3; i < tokens.size(); i++)
1668 m_answer += QString(
" ") + tokens[i];
1671 else if ((tokens.size() >= 4) &&
1672 (tokens[1] ==
"RESPONSE"))
1676 for (
int i = 4; i < tokens.size(); i++)
1677 m_answer += QString(
" ") + tokens[i];
1703 for (
auto * ncc2 : std::as_const(
m_clients))
1715 if (ncce ==
nullptr)
1727 bool appendCRLF =
true;
1728 QString queryStr(
"SELECT chanid, starttime, endtime, title, subtitle "
1730 "WHERE starttime < :START AND endtime > :END ");
1732 if (!chanID.isEmpty())
1734 queryStr +=
" AND chanid = :CHANID";
1738 queryStr +=
" ORDER BY starttime, endtime, chanid";
1743 if (!chanID.isEmpty())
1750 while (query.
next())
1752 QString title = query.
value(3).toString();
1753 QString subtitle = query.
value(4).toString();
1755 if (!subtitle.isEmpty())
1756 title += QString(
" -\"%1\"").arg(subtitle);
1757 QByteArray atitle = title.toLocal8Bit();
1760 QString(
"%1 %2 %3 %4")
1761 .arg(QString::number(query.
value(0).toInt()).rightJustified(5,
' '),
1772 result =
"ERROR: Unable to retrieve current schedule list.";
1782 bool appendCRLF =
true;
1784 queryStr =
"SELECT chanid, starttime, title, subtitle "
1785 "FROM recorded WHERE deletepending = 0 ";
1787 if ((!chanid.isEmpty()) && (!starttime.isEmpty()))
1789 queryStr +=
"AND chanid = " + chanid +
" "
1790 "AND starttime = '" + starttime +
"' ";
1794 queryStr +=
"ORDER BY starttime, title;";
1802 while (query.
next())
1804 title = query.
value(2).toString();
1805 subtitle = query.
value(3).toString();
1807 if (!subtitle.isEmpty())
1809 episode = QString(
"%1 -\"%2\"").arg(title, subtitle);
1818 .arg(query.
value(0).toString(),
1828 result =
"ERROR: Unable to retrieve recordings list.";
1839 uint sqlStart = start;
1845 queryStr =
"select chanid, callsign, name from channel "
1846 "where deleted IS NULL and visible > 0 "
1847 "ORDER BY callsign";
1851 QString limitStr = QString(
" LIMIT %1,%2").arg(sqlStart).arg(limit);
1852 queryStr += limitStr;
1858 result =
"ERROR: Unable to retrieve channel list.";
1866 result += QString(R
"(0:0 0 "Invalid" "Invalid")");
1870 while (query.
next())
1875 result += QString(
"%1:%2 %3 \"%4\" \"%5\"\r\n")
1876 .arg(cnt).arg(maxcnt)
1877 .arg(query.
value(0).toString(),
1878 query.
value(1).toString(),
1879 query.
value(2).toString());
1892 QStringList size = nc->
getArg(1).split(
'x');
1893 if (size.size() == 2)
1895 width = size[0].toInt();
1896 height = size[1].toInt();
1902 if (width && height)
1904 args << QString::number(width);
1905 args << QString::number(height);
1909 qApp->postEvent(window, me);
1916 for(
int i=0 ; i<arg ; i++) {
1917 QString argstr = c.simplified().split(
" ")[0];
1918 c = c.mid(argstr.length()).trimmed();
1923#include "moc_networkcontrol.cpp"
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