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 : qAsConst(command))
166 if (!bInString && c ==
'"')
168 else if (bInString && c ==
'"')
170 else if (!bInString && c ==
' ')
190 if (tokens[0] ==
"HALT" ||
191 tokens[0] ==
"QUIT" ||
192 tokens[0] ==
"SHUTDOWN")
196 else if (tokens[0] ==
"HELLO")
200 else if (tokens[0] ==
"SWITCH_TO_TIME")
204 else if (tokens[0] ==
"SWITCH_TO_MUSIC")
208 else if (tokens[0] ==
"SWITCH_TO_VOLUME")
212 else if (tokens[0] ==
"SWITCH_TO_GENERIC")
216 else if (tokens[0] ==
"SWITCH_TO_MENU")
220 else if (tokens[0] ==
"SWITCH_TO_CHANNEL")
224 else if (tokens[0] ==
"SWITCH_TO_NOTHING")
228 else if (tokens[0] ==
"SET_VOLUME_LEVEL")
232 else if (tokens[0] ==
"SET_GENERIC_PROGRESS")
236 else if (tokens[0] ==
"SET_MUSIC_PROGRESS")
240 else if (tokens[0] ==
"SET_MUSIC_PLAYER_PROP")
244 else if (tokens[0] ==
"SET_CHANNEL_PROGRESS")
248 else if (tokens[0] ==
"UPDATE_LEDS")
252 else if (tokens[0] ==
"STOP_ALL")
257 else if (tokens[0] ==
"RESET")
265 QString did_not_parse = tokens.join(
" ");
268 LOG(VB_GENERAL, LOG_ERR,
"LCDServer::failed to parse this: " +
278 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: shuting down");
290 QString message = what;
291 message.append(
"\n");
292 QByteArray
tmp = message.toUtf8();
293 where->write(
tmp.constData(),
tmp.length());
299 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: send key press: " + key_pressed);
319 sWidth = sWidth.setNum(nWidth);
320 sHeight = sHeight.setNum(nHeight);
322 sendMessage(socket,
"CONNECTED " + sWidth +
" " + sHeight);
328 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: SWITCH_TO_TIME");
339 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_MUSIC");
341 QString flat = tokens.join(
" ");
343 if (tokens.count() != 4)
345 LOG(VB_GENERAL, LOG_ERR,
346 "LCDServer: bad SWITCH_TO_MUSIC command: " + flat);
360 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_GENERIC");
362 QString flat = tokens.join(
" ");
364 if ((tokens.count() - 1) % 5 != 0)
366 LOG(VB_GENERAL, LOG_ERR,
367 "LCDServer: bad no. of args SWITCH_TO_GENERIC command: " + flat);
372 QList<LCDTextItem> items;
374 for (
int x = 1; x < tokens.count(); x += 5)
377 int row = tokens[x].toInt(&bOK);
380 LOG(VB_GENERAL, LOG_ERR,
381 "LCDServer: bad row no. in SWITCH_TO_GENERIC "
382 "command: " + tokens[x]);
388 if (tokens[x + 1] ==
"ALIGN_LEFT")
390 else if (tokens[x + 1] ==
"ALIGN_RIGHT")
392 else if (tokens[x + 1] ==
"ALIGN_CENTERED")
396 LOG(VB_GENERAL, LOG_ERR,
397 "LCDServer: bad align in SWITCH_TO_GENERIC command: " +
403 const QString& text = tokens[x + 2];
404 const QString& screen = tokens[x + 3];
405 bool scrollable =
false;
406 if (tokens[x + 4] ==
"TRUE")
408 else if (tokens[x + 4] ==
"FALSE")
412 LOG(VB_GENERAL, LOG_ERR,
413 "LCDServer: bad scrollable bool in SWITCH_TO_GENERIC "
414 "command: " + tokens[x + 4]);
419 items.append(
LCDTextItem(row, align, text, screen, scrollable));
431 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_CHANNEL");
433 QString flat = tokens.join(
" ");
435 if (tokens.count() != 4)
437 LOG(VB_GENERAL, LOG_ERR,
438 "LCDServer: bad SWITCH_TO_CHANNEL command: " + flat);
452 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_VOLUME");
454 QString flat = tokens.join(
" ");
456 if (tokens.count() != 2)
458 LOG(VB_GENERAL, LOG_ERR,
459 "LCDServer: bad SWITCH_TO_VOLUME command: " + flat);
473 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_NOTHING");
484 LOG(VB_GENERAL, LOG_INFO,
485 QString(
"LCDServer: SWITCH_TO_MENU: %1").arg(tokens.count()));
487 QString flat = tokens.join(
" ");
489 if ((tokens.count() - 3) % 5 != 0)
491 LOG(VB_GENERAL, LOG_ERR,
492 "LCDServer: bad no. of args SWITCH_TO_MENU command: " + flat);
497 const QString& appName = tokens[1];
500 if (tokens[2] ==
"TRUE")
502 else if (tokens[2] ==
"FALSE")
506 LOG(VB_GENERAL, LOG_ERR,
507 "LCDServer: bad popup bool in SWITCH_TO_MENU command: " +
513 QList<LCDMenuItem> items;
515 for (
int x = 3; x < tokens.count(); x += 5)
517 const QString& text = tokens[x];
520 if (tokens[x + 1] ==
"CHECKED")
522 else if (tokens[x + 1] ==
"UNCHECKED")
524 else if (tokens[x + 1] ==
"NOTCHECKABLE")
528 LOG(VB_GENERAL, LOG_ERR,
529 "LCDServer: bad checked state in SWITCH_TO_MENU command: " +
535 bool selected =
false;
536 if (tokens[x + 2] ==
"TRUE")
538 else if (tokens[x + 2] ==
"FALSE")
542 LOG(VB_GENERAL, LOG_ERR,
543 "LCDServer: bad selected state in SWITCH_TO_MENU command: " +
549 bool scrollable =
false;
550 if (tokens[x + 3] ==
"TRUE")
552 else if (tokens[x + 3] ==
"FALSE")
556 LOG(VB_GENERAL, LOG_ERR,
557 "LCDServer: bad scrollable bool in SWITCH_TO_MENU command: " +
564 int indent = tokens[x + 4].toInt(&bOK);
567 LOG(VB_GENERAL, LOG_ERR,
568 "LCDServer: bad indent in SWITCH_TO_MENU command: " +
586 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_CHANNEL_PROGRESS");
588 QString flat = tokens.join(
" ");
590 if (tokens.count() != 3)
592 LOG(VB_GENERAL, LOG_ERR,
593 "LCDServer: bad SET_CHANNEL_PROGRESS command: " + flat);
599 float progress = tokens[2].toFloat(&bOK);
602 LOG(VB_GENERAL, LOG_ERR,
603 QString(
"LCDServer: bad float value in SET_CHANNEL_PROGRESS "
604 "command: %1").arg(tokens[2]));
618 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_GENERIC_PROGRESS");
620 QString flat = tokens.join(
" ");
622 if (tokens.count() != 3)
624 LOG(VB_GENERAL, LOG_ERR,
625 "LCDServer: bad SET_GENERIC_PROGRESS command: " + flat);
631 bool busy = tokens[1].toInt(&bOK) != 0;
634 LOG(VB_GENERAL, LOG_ERR,
635 QString(
"LCDServer: bad bool value in SET_GENERIC_PROGRESS "
636 "command: %1 %2").arg(tokens[1], tokens[2]));
640 float progress = tokens[2].toFloat(&bOK);
643 LOG(VB_GENERAL, LOG_ERR,
644 QString(
"LCDServer: bad float value in SET_GENERIC_PROGRESS "
645 "command: %1").arg(tokens[2]));
659 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_MUSIC_PROGRESS");
661 QString flat = tokens.join(
" ");
663 if (tokens.count() != 3)
665 LOG(VB_GENERAL, LOG_ERR,
666 "LCDServer: bad SET_MUSIC_PROGRESS command: " + flat);
672 float progress = tokens[2].toFloat(&bOK);
675 LOG(VB_GENERAL, LOG_ERR,
676 "LCDServer: bad float value in SET_MUSIC_PROGRESS command: " +
691 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_MUSIC_PROP");
693 QString flat = tokens.join(
" ");
695 if (tokens.count() < 3)
697 LOG(VB_GENERAL, LOG_ERR,
698 "LCDServer: bad SET_MUSIC_PROP command: " + flat);
703 if (tokens[1] ==
"SHUFFLE")
705 if (tokens.count () != 3)
707 LOG(VB_GENERAL, LOG_ERR,
708 "LCDServer: missing argument for SET_MUSIC_PROP SHUFFLE "
714 int state = tokens[2].toInt (&bOk);
717 LOG(VB_GENERAL, LOG_ERR,
718 "LCDServer: bad argument for SET_MUSIC_PROP SHUFFLE "
719 "command: " + tokens[2]);
726 else if (tokens[1] ==
"REPEAT")
728 if (tokens.count () != 3)
730 LOG(VB_GENERAL, LOG_ERR,
731 "LCDServer: missing argument for SET_MUSIC_PROP REPEAT "
737 int state = tokens[2].toInt (&bOk);
740 LOG(VB_GENERAL, LOG_ERR,
741 "LCDServer: bad argument for SET_MUSIC_PROP REPEAT command: " +
751 LOG(VB_GENERAL, LOG_ERR,
752 "LCDServer: bad argument for SET_MUSIC_PROP command: " + tokens[1]);
763 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_VOLUME_LEVEL");
765 QString flat = tokens.join(
" ");
767 if (tokens.count() != 2)
769 LOG(VB_GENERAL, LOG_ERR,
770 "LCDServer: bad SET_VOLUME_LEVEL command: " + flat);
776 float progress = tokens[1].toFloat(&bOK);
779 LOG(VB_GENERAL, LOG_ERR,
780 "LCDServer: bad float value in SET_VOLUME_LEVEL command: " +
795 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: UPDATE_LEDS");
797 QString flat = tokens.join(
" ");
799 if (tokens.count() != 2)
801 LOG(VB_GENERAL, LOG_ERR,
"LCDServer: bad UPDATE_LEDs command: " + flat);
807 int mask = tokens[1].toInt(&bOK);
810 LOG(VB_GENERAL, LOG_ERR,
811 "LCDServer: bad mask in UPDATE_LEDS command: " + tokens[1]);