60 #include <QCoreApplication>
64 #include <QStringList>
75 #define LOC QString("LCDServer: ")
76 #define LOC_WARN QString("LCDServer, Warning: ")
77 #define LOC_ERR QString("LCDServer, Error: ")
95 LOG(VB_GENERAL, LOG_ERR,
"There is probably a copy of mythlcdserver "
96 "already running. You can verify this by running: \n"
97 "'ps ax | grep mythlcdserver'");
108 connect(socket, &QIODevice::readyRead,
110 connect(socket, &QAbstractSocket::disconnected,
114 LOG(VB_NETWORK, LOG_INFO,
"LCDServer: new connection");
122 auto *socket = qobject_cast<QTcpSocket*>(sender());
126 socket->deleteLater();
128 LOG(VB_NETWORK, LOG_INFO,
"LCDServer: close connection");
137 auto *socket = qobject_cast<QTcpSocket*>(sender());
142 while(socket->canReadLine())
144 QString incoming_data = socket->readLine();
145 incoming_data = incoming_data.replace( QRegExp(
"\n"),
"" );
146 incoming_data = incoming_data.replace( QRegExp(
"\r"),
"" );
147 incoming_data = incoming_data.simplified();
159 bool bInString =
false;
161 for (
auto && x : qAsConst(command))
164 if (!bInString && c ==
'"')
166 else if (bInString && c ==
'"')
168 else if (!bInString && c ==
' ')
188 if (tokens[0] ==
"HALT" ||
189 tokens[0] ==
"QUIT" ||
190 tokens[0] ==
"SHUTDOWN")
194 else if (tokens[0] ==
"HELLO")
198 else if (tokens[0] ==
"SWITCH_TO_TIME")
202 else if (tokens[0] ==
"SWITCH_TO_MUSIC")
206 else if (tokens[0] ==
"SWITCH_TO_VOLUME")
210 else if (tokens[0] ==
"SWITCH_TO_GENERIC")
214 else if (tokens[0] ==
"SWITCH_TO_MENU")
218 else if (tokens[0] ==
"SWITCH_TO_CHANNEL")
222 else if (tokens[0] ==
"SWITCH_TO_NOTHING")
226 else if (tokens[0] ==
"SET_VOLUME_LEVEL")
230 else if (tokens[0] ==
"SET_GENERIC_PROGRESS")
234 else if (tokens[0] ==
"SET_MUSIC_PROGRESS")
238 else if (tokens[0] ==
"SET_MUSIC_PLAYER_PROP")
242 else if (tokens[0] ==
"SET_CHANNEL_PROGRESS")
246 else if (tokens[0] ==
"UPDATE_LEDS")
250 else if (tokens[0] ==
"STOP_ALL")
255 else if (tokens[0] ==
"RESET")
263 QString did_not_parse = tokens.join(
" ");
266 LOG(VB_GENERAL, LOG_ERR,
"LCDServer::failed to parse this: " +
276 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: shuting down");
288 QString message = what;
289 message.append(
"\n");
290 QByteArray
tmp = message.toUtf8();
291 where->write(
tmp.constData(),
tmp.length());
297 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: send key press: " + key_pressed);
317 sWidth = sWidth.setNum(nWidth);
318 sHeight = sHeight.setNum(nHeight);
320 sendMessage(socket,
"CONNECTED " + sWidth +
" " + sHeight);
326 LOG(VB_GENERAL, LOG_INFO,
"LCDServer:: SWITCH_TO_TIME");
337 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_MUSIC");
339 QString flat = tokens.join(
" ");
341 if (tokens.count() != 4)
343 LOG(VB_GENERAL, LOG_ERR,
344 "LCDServer: bad SWITCH_TO_MUSIC command: " + flat);
358 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_GENERIC");
360 QString flat = tokens.join(
" ");
362 if ((tokens.count() - 1) % 5 != 0)
364 LOG(VB_GENERAL, LOG_ERR,
365 "LCDServer: bad no. of args SWITCH_TO_GENERIC command: " + flat);
370 QList<LCDTextItem> items;
372 for (
int x = 1; x < tokens.count(); x += 5)
375 int row = tokens[x].toInt(&bOK);
378 LOG(VB_GENERAL, LOG_ERR,
379 "LCDServer: bad row no. in SWITCH_TO_GENERIC "
380 "command: " + tokens[x]);
386 if (tokens[x + 1] ==
"ALIGN_LEFT")
388 else if (tokens[x + 1] ==
"ALIGN_RIGHT")
390 else if (tokens[x + 1] ==
"ALIGN_CENTERED")
394 LOG(VB_GENERAL, LOG_ERR,
395 "LCDServer: bad align in SWITCH_TO_GENERIC command: " +
401 QString text = tokens[x + 2];
402 QString screen = tokens[x + 3];
403 bool scrollable =
false;
404 if (tokens[x + 4] ==
"TRUE")
406 else if (tokens[x + 4] ==
"FALSE")
410 LOG(VB_GENERAL, LOG_ERR,
411 "LCDServer: bad scrollable bool in SWITCH_TO_GENERIC "
412 "command: " + tokens[x + 4]);
417 items.append(
LCDTextItem(row, align, text, screen, scrollable));
429 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_CHANNEL");
431 QString flat = tokens.join(
" ");
433 if (tokens.count() != 4)
435 LOG(VB_GENERAL, LOG_ERR,
436 "LCDServer: bad SWITCH_TO_CHANNEL command: " + flat);
450 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_VOLUME");
452 QString flat = tokens.join(
" ");
454 if (tokens.count() != 2)
456 LOG(VB_GENERAL, LOG_ERR,
457 "LCDServer: bad SWITCH_TO_VOLUME command: " + flat);
471 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SWITCH_TO_NOTHING");
482 LOG(VB_GENERAL, LOG_INFO,
483 QString(
"LCDServer: SWITCH_TO_MENU: %1").
arg(tokens.count()));
485 QString flat = tokens.join(
" ");
487 if ((tokens.count() - 3) % 5 != 0)
489 LOG(VB_GENERAL, LOG_ERR,
490 "LCDServer: bad no. of args SWITCH_TO_MENU command: " + flat);
495 QString appName = tokens[1];
498 if (tokens[2] ==
"TRUE")
500 else if (tokens[2] ==
"FALSE")
504 LOG(VB_GENERAL, LOG_ERR,
505 "LCDServer: bad popup bool in SWITCH_TO_MENU command: " +
511 QList<LCDMenuItem> items;
513 for (
int x = 3; x < tokens.count(); x += 5)
515 QString text = tokens[x];
518 if (tokens[x + 1] ==
"CHECKED")
520 else if (tokens[x + 1] ==
"UNCHECKED")
522 else if (tokens[x + 1] ==
"NOTCHECKABLE")
526 LOG(VB_GENERAL, LOG_ERR,
527 "LCDServer: bad checked state in SWITCH_TO_MENU command: " +
533 bool selected =
false;
534 if (tokens[x + 2] ==
"TRUE")
536 else if (tokens[x + 2] ==
"FALSE")
540 LOG(VB_GENERAL, LOG_ERR,
541 "LCDServer: bad selected state in SWITCH_TO_MENU command: " +
547 bool scrollable =
false;
548 if (tokens[x + 3] ==
"TRUE")
550 else if (tokens[x + 3] ==
"FALSE")
554 LOG(VB_GENERAL, LOG_ERR,
555 "LCDServer: bad scrollable bool in SWITCH_TO_MENU command: " +
562 int indent = tokens[x + 4].toInt(&bOK);
565 LOG(VB_GENERAL, LOG_ERR,
566 "LCDServer: bad indent in SWITCH_TO_MENU command: " +
584 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_CHANNEL_PROGRESS");
586 QString flat = tokens.join(
" ");
588 if (tokens.count() != 3)
590 LOG(VB_GENERAL, LOG_ERR,
591 "LCDServer: bad SET_CHANNEL_PROGRESS command: " + flat);
597 float progress = tokens[2].toFloat(&bOK);
600 LOG(VB_GENERAL, LOG_ERR,
601 QString(
"LCDServer: bad float value in SET_CHANNEL_PROGRESS "
602 "command: %1").
arg(tokens[2]));
616 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_GENERIC_PROGRESS");
618 QString flat = tokens.join(
" ");
620 if (tokens.count() != 3)
622 LOG(VB_GENERAL, LOG_ERR,
623 "LCDServer: bad SET_GENERIC_PROGRESS command: " + flat);
629 bool busy = tokens[1].toInt(&bOK) != 0;
632 LOG(VB_GENERAL, LOG_ERR,
633 QString(
"LCDServer: bad bool value in SET_GENERIC_PROGRESS "
634 "command: %1 %2").
arg(tokens[1]).
arg(tokens[2]));
638 float progress = tokens[2].toFloat(&bOK);
641 LOG(VB_GENERAL, LOG_ERR,
642 QString(
"LCDServer: bad float value in SET_GENERIC_PROGRESS "
643 "command: %1").
arg(tokens[2]));
657 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_MUSIC_PROGRESS");
659 QString flat = tokens.join(
" ");
661 if (tokens.count() != 3)
663 LOG(VB_GENERAL, LOG_ERR,
664 "LCDServer: bad SET_MUSIC_PROGRESS command: " + flat);
670 float progress = tokens[2].toFloat(&bOK);
673 LOG(VB_GENERAL, LOG_ERR,
674 "LCDServer: bad float value in SET_MUSIC_PROGRESS command: " +
689 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_MUSIC_PROP");
691 QString flat = tokens.join(
" ");
693 if (tokens.count() < 3)
695 LOG(VB_GENERAL, LOG_ERR,
696 "LCDServer: bad SET_MUSIC_PROP command: " + flat);
701 if (tokens[1] ==
"SHUFFLE")
703 if (tokens.count () != 3)
705 LOG(VB_GENERAL, LOG_ERR,
706 "LCDServer: missing argument for SET_MUSIC_PROP SHUFFLE "
712 int state = tokens[2].toInt (&bOk);
715 LOG(VB_GENERAL, LOG_ERR,
716 "LCDServer: bad argument for SET_MUSIC_PROP SHUFFLE "
717 "command: " + tokens[2]);
724 else if (tokens[1] ==
"REPEAT")
726 if (tokens.count () != 3)
728 LOG(VB_GENERAL, LOG_ERR,
729 "LCDServer: missing argument for SET_MUSIC_PROP REPEAT "
735 int state = tokens[2].toInt (&bOk);
738 LOG(VB_GENERAL, LOG_ERR,
739 "LCDServer: bad argument for SET_MUSIC_PROP REPEAT command: " +
749 LOG(VB_GENERAL, LOG_ERR,
750 "LCDServer: bad argument for SET_MUSIC_PROP command: " + tokens[1]);
761 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: SET_VOLUME_LEVEL");
763 QString flat = tokens.join(
" ");
765 if (tokens.count() != 2)
767 LOG(VB_GENERAL, LOG_ERR,
768 "LCDServer: bad SET_VOLUME_LEVEL command: " + flat);
774 float progress = tokens[1].toFloat(&bOK);
777 LOG(VB_GENERAL, LOG_ERR,
778 "LCDServer: bad float value in SET_VOLUME_LEVEL command: " +
793 LOG(VB_GENERAL, LOG_INFO,
"LCDServer: UPDATE_LEDS");
795 QString flat = tokens.join(
" ");
797 if (tokens.count() != 2)
799 LOG(VB_GENERAL, LOG_ERR,
"LCDServer: bad UPDATE_LEDs command: " + flat);
805 int mask = tokens[1].toInt(&bOK);
808 LOG(VB_GENERAL, LOG_ERR,
809 "LCDServer: bad mask in UPDATE_LEDS command: " + tokens[1]);