63 #include <QCoreApplication>
66 #include <QStringList>
78 #define LOC QString("LCDServer: ")
79 #define LOC_WARN QString("LCDServer, Warning: ")
80 #define LOC_ERR QString("LCDServer, Error: ")
97 LOG(VB_GENERAL, LOG_ERR,
"There is probably a copy of mythlcdserver "
98 "already running. You can verify this by running: \n"
99 "'ps ax | grep mythlcdserver'");
110 connect(socket, &QIODevice::readyRead,
112 connect(socket, &QAbstractSocket::disconnected,
116 LOG(VB_NETWORK, LOG_INFO,
"LCDServer: new connection");
124 auto *socket = qobject_cast<QTcpSocket*>(sender());
128 socket->deleteLater();
130 LOG(VB_NETWORK, LOG_INFO,
"LCDServer: close connection");
139 auto *socket = qobject_cast<QTcpSocket*>(sender());
144 while(socket->canReadLine())
146 QString incoming_data = socket->readLine();
147 incoming_data = incoming_data.remove(
"\n");
148 incoming_data = incoming_data.remove(
"\r");
149 incoming_data = incoming_data.simplified();
161 bool bInString =
false;
163 for (
auto && x : std::as_const(command))
166 if (!bInString && c ==
'"')
168 else if (bInString && c ==
'"')
170 else if (!bInString && c ==
' ')
192 if (tokens[0] ==
"HALT" ||
193 tokens[0] ==
"QUIT" ||
194 tokens[0] ==
"SHUTDOWN")
198 else if (tokens[0] ==
"HELLO")
202 else if (tokens[0] ==
"SWITCH_TO_TIME")
206 else if (tokens[0] ==
"SWITCH_TO_MUSIC")
210 else if (tokens[0] ==
"SWITCH_TO_VOLUME")
214 else if (tokens[0] ==
"SWITCH_TO_GENERIC")
218 else if (tokens[0] ==
"SWITCH_TO_MENU")
222 else if (tokens[0] ==
"SWITCH_TO_CHANNEL")
226 else if (tokens[0] ==
"SWITCH_TO_NOTHING")
230 else if (tokens[0] ==
"SET_VOLUME_LEVEL")
234 else if (tokens[0] ==
"SET_GENERIC_PROGRESS")
238 else if (tokens[0] ==
"SET_MUSIC_PROGRESS")
242 else if (tokens[0] ==
"SET_MUSIC_PLAYER_PROP")
246 else if (tokens[0] ==
"SET_CHANNEL_PROGRESS")
250 else if (tokens[0] ==
"UPDATE_LEDS")
254 else if (tokens[0] ==
"STOP_ALL")
259 else if (tokens[0] ==
"RESET")
267 QString did_not_parse = tokens.join(
" ");
270 LOG(VB_GENERAL, LOG_ERR,
"LCDServer::failed to parse this: " +
280 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: shuting down");
292 QString message = what;
293 message.append(
"\n");
294 QByteArray
tmp = message.toUtf8();
295 where->write(
tmp.constData(),
tmp.length());
301 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: send key press: " + key_pressed);
321 sWidth = sWidth.setNum(nWidth);
322 sHeight = sHeight.setNum(nHeight);
324 sendMessage(socket,
"CONNECTED " + sWidth +
" " + sHeight);
330 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: SWITCH_TO_TIME");
341 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_MUSIC");
343 QString flat = tokens.join(
" ");
345 if (tokens.count() != 4)
347 LOG(VB_GENERAL, LOG_ERR,
348 "LCDServer: bad SWITCH_TO_MUSIC command: " + flat);
362 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_GENERIC");
364 QString flat = tokens.join(
" ");
366 if ((tokens.count() - 1) % 5 != 0)
368 LOG(VB_GENERAL, LOG_ERR,
369 "LCDServer: bad no. of args SWITCH_TO_GENERIC command: " + flat);
374 QList<LCDTextItem> items;
376 for (
int x = 1; x < tokens.count(); x += 5)
379 int row = tokens[x].toInt(&bOK);
382 LOG(VB_GENERAL, LOG_ERR,
383 "LCDServer: bad row no. in SWITCH_TO_GENERIC "
384 "command: " + tokens[x]);
390 if (tokens[x + 1] ==
"ALIGN_LEFT")
392 else if (tokens[x + 1] ==
"ALIGN_RIGHT")
394 else if (tokens[x + 1] ==
"ALIGN_CENTERED")
398 LOG(VB_GENERAL, LOG_ERR,
399 "LCDServer: bad align in SWITCH_TO_GENERIC command: " +
405 const QString& text = tokens[x + 2];
406 const QString& screen = tokens[x + 3];
407 bool scrollable =
false;
408 if (tokens[x + 4] ==
"TRUE")
410 else if (tokens[x + 4] ==
"FALSE")
414 LOG(VB_GENERAL, LOG_ERR,
415 "LCDServer: bad scrollable bool in SWITCH_TO_GENERIC "
416 "command: " + tokens[x + 4]);
421 items.append(
LCDTextItem(row, align, text, screen, scrollable));
433 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_CHANNEL");
435 QString flat = tokens.join(
" ");
437 if (tokens.count() != 4)
439 LOG(VB_GENERAL, LOG_ERR,
440 "LCDServer: bad SWITCH_TO_CHANNEL command: " + flat);
454 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_VOLUME");
456 QString flat = tokens.join(
" ");
458 if (tokens.count() != 2)
460 LOG(VB_GENERAL, LOG_ERR,
461 "LCDServer: bad SWITCH_TO_VOLUME command: " + flat);
475 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_NOTHING");
486 LOG(VB_GENERAL, LOG_INFO,
487 QString(
"LCDServer: SWITCH_TO_MENU: %1").arg(tokens.count()));
489 QString flat = tokens.join(
" ");
491 if ((tokens.count() - 3) % 5 != 0)
493 LOG(VB_GENERAL, LOG_ERR,
494 "LCDServer: bad no. of args SWITCH_TO_MENU command: " + flat);
499 const QString& appName = tokens[1];
502 if (tokens[2] ==
"TRUE")
504 else if (tokens[2] ==
"FALSE")
508 LOG(VB_GENERAL, LOG_ERR,
509 "LCDServer: bad popup bool in SWITCH_TO_MENU command: " +
515 QList<LCDMenuItem> items;
517 for (
int x = 3; x < tokens.count(); x += 5)
519 const QString& text = tokens[x];
522 if (tokens[x + 1] ==
"CHECKED")
524 else if (tokens[x + 1] ==
"UNCHECKED")
526 else if (tokens[x + 1] ==
"NOTCHECKABLE")
530 LOG(VB_GENERAL, LOG_ERR,
531 "LCDServer: bad checked state in SWITCH_TO_MENU command: " +
537 bool selected =
false;
538 if (tokens[x + 2] ==
"TRUE")
540 else if (tokens[x + 2] ==
"FALSE")
544 LOG(VB_GENERAL, LOG_ERR,
545 "LCDServer: bad selected state in SWITCH_TO_MENU command: " +
551 bool scrollable =
false;
552 if (tokens[x + 3] ==
"TRUE")
554 else if (tokens[x + 3] ==
"FALSE")
558 LOG(VB_GENERAL, LOG_ERR,
559 "LCDServer: bad scrollable bool in SWITCH_TO_MENU command: " +
566 int indent = tokens[x + 4].toInt(&bOK);
569 LOG(VB_GENERAL, LOG_ERR,
570 "LCDServer: bad indent in SWITCH_TO_MENU command: " +
588 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_CHANNEL_PROGRESS");
590 QString flat = tokens.join(
" ");
592 if (tokens.count() != 3)
594 LOG(VB_GENERAL, LOG_ERR,
595 "LCDServer: bad SET_CHANNEL_PROGRESS command: " + flat);
601 float progress = tokens[2].toFloat(&bOK);
604 LOG(VB_GENERAL, LOG_ERR,
605 QString(
"LCDServer: bad float value in SET_CHANNEL_PROGRESS "
606 "command: %1").arg(tokens[2]));
620 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_GENERIC_PROGRESS");
622 QString flat = tokens.join(
" ");
624 if (tokens.count() != 3)
626 LOG(VB_GENERAL, LOG_ERR,
627 "LCDServer: bad SET_GENERIC_PROGRESS command: " + flat);
633 bool busy = tokens[1].toInt(&bOK) != 0;
636 LOG(VB_GENERAL, LOG_ERR,
637 QString(
"LCDServer: bad bool value in SET_GENERIC_PROGRESS "
638 "command: %1 %2").arg(tokens[1], tokens[2]));
642 float progress = tokens[2].toFloat(&bOK);
645 LOG(VB_GENERAL, LOG_ERR,
646 QString(
"LCDServer: bad float value in SET_GENERIC_PROGRESS "
647 "command: %1").arg(tokens[2]));
661 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_MUSIC_PROGRESS");
663 QString flat = tokens.join(
" ");
665 if (tokens.count() != 3)
667 LOG(VB_GENERAL, LOG_ERR,
668 "LCDServer: bad SET_MUSIC_PROGRESS command: " + flat);
674 float progress = tokens[2].toFloat(&bOK);
677 LOG(VB_GENERAL, LOG_ERR,
678 "LCDServer: bad float value in SET_MUSIC_PROGRESS command: " +
693 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_MUSIC_PROP");
695 QString flat = tokens.join(
" ");
697 if (tokens.count() < 3)
699 LOG(VB_GENERAL, LOG_ERR,
700 "LCDServer: bad SET_MUSIC_PROP command: " + flat);
705 if (tokens[1] ==
"SHUFFLE")
707 if (tokens.count () != 3)
709 LOG(VB_GENERAL, LOG_ERR,
710 "LCDServer: missing argument for SET_MUSIC_PROP SHUFFLE "
716 int state = tokens[2].toInt (&bOk);
719 LOG(VB_GENERAL, LOG_ERR,
720 "LCDServer: bad argument for SET_MUSIC_PROP SHUFFLE "
721 "command: " + tokens[2]);
728 else if (tokens[1] ==
"REPEAT")
730 if (tokens.count () != 3)
732 LOG(VB_GENERAL, LOG_ERR,
733 "LCDServer: missing argument for SET_MUSIC_PROP REPEAT "
739 int state = tokens[2].toInt (&bOk);
742 LOG(VB_GENERAL, LOG_ERR,
743 "LCDServer: bad argument for SET_MUSIC_PROP REPEAT command: " +
753 LOG(VB_GENERAL, LOG_ERR,
754 "LCDServer: bad argument for SET_MUSIC_PROP command: " + tokens[1]);
765 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_VOLUME_LEVEL");
767 QString flat = tokens.join(
" ");
769 if (tokens.count() != 2)
771 LOG(VB_GENERAL, LOG_ERR,
772 "LCDServer: bad SET_VOLUME_LEVEL command: " + flat);
778 float progress = tokens[1].toFloat(&bOK);
781 LOG(VB_GENERAL, LOG_ERR,
782 "LCDServer: bad float value in SET_VOLUME_LEVEL command: " +
797 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: UPDATE_LEDS");
799 QString flat = tokens.join(
" ");
801 if (tokens.count() != 2)
803 LOG(VB_GENERAL, LOG_ERR,
"LCDServer: bad UPDATE_LEDs command: " + flat);
809 int mask = tokens[1].toInt(&bOK);
812 LOG(VB_GENERAL, LOG_ERR,
813 "LCDServer: bad mask in UPDATE_LEDS command: " + tokens[1]);