Go to the documentation of this file.
19 #include <QApplication>
20 #include <QTextStream>
22 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
23 #include <QStringConverter>
42 #define LOC QString("LCDdevice: ")
45 : m_retryTimer(new QTimer(this)), m_ledTimer(new QTimer(this))
57 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
58 "An LCD object now exists (LCD() was called)");
87 lcd_host =
GetMythDB()->GetSetting(
"LCDServerHost",
"localhost");
88 int lcd_port =
GetMythDB()->GetNumSetting(
"LCDServerPort", 6545);
92 if (lcd_host ==
"localhost")
93 lcd_host =
"127.0.0.1";
95 if (
m_enabled && lcd_host.length() > 0 && lcd_port > 1024)
111 LOG(VB_NETWORK, LOG_DEBUG,
LOC +
112 QString(
"connecting to host: %1 - port: %2")
113 .arg(lhostname).arg(lport));
130 if (
myth_system(
"ps ch -C mythlcdserver -o pid > /dev/null", flags) == 1)
133 LOG(VB_GENERAL, LOG_NOTICE,
"Starting mythlcdserver");
137 LOG(VB_GENERAL, LOG_ERR,
"Failed start MythTV LCD Server");
151 LOG(VB_GENERAL, LOG_INFO, QString(
"Connecting to lcd server: "
158 QObject::connect(
m_socket, &QIODevice::readyRead,
160 QObject::connect(
m_socket, &QAbstractSocket::disconnected,
194 if (
m_socket->thread() != QThread::currentThread())
196 LOG(VB_GENERAL, LOG_ERR,
197 "Sending to LCDServer from wrong thread.");
202 if (QAbstractSocket::ConnectedState !=
m_socket->state())
210 LOG(VB_GENERAL, LOG_ERR,
211 "Connection to LCDServer died unexpectedly. "
212 "Trying to reconnect every 10 seconds...");
219 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
220 os.setCodec(QTextCodec::codecForName(
"ISO 8859-1"));
222 os.setEncoding(QStringConverter::Latin1);
229 LOG(VB_NETWORK, LOG_DEBUG,
LOC +
230 QString(
"Sending to Server: %1").arg(someText));
233 os << someText <<
"\n";
262 QString lineFromServer;
271 int dataSize =
static_cast<int>(
m_socket->bytesAvailable() + 1);
272 QByteArray data(dataSize + 1, 0);
274 m_socket->read(data.data(), dataSize);
276 lineFromServer = data;
277 lineFromServer = lineFromServer.simplified();
280 if (lineFromServer !=
"OK")
281 LOG(VB_NETWORK, LOG_DEBUG,
LOC + QString(
"Received from server: %1")
282 .arg(lineFromServer));
284 aList = lineFromServer.split(
' ');
285 if (aList[0] ==
"CONNECTED")
289 if (aList.count() != 3)
291 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad no. of arguments in "
292 "CONNECTED response from LCDServer");
299 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad int for width in "
300 "CONNECTED response from LCDServer");
306 LOG(VB_GENERAL, LOG_ERR,
LOC +
"received bad int for height in "
307 "CONNECTED response from LCDServer");
312 else if (aList[0] ==
"HUH?")
314 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Something is getting passed to "
315 "LCDServer that it does not understand");
316 LOG(VB_GENERAL, LOG_WARNING,
LOC +
319 else if (aList[0] ==
"KEY")
327 QChar mykey = keyPressed.at(0);
339 key = Qt::Key_Escape;
341 QCoreApplication::postEvent(
342 (QObject *)(QApplication::activeWindow()),
382 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"stopAll");
472 value = std::min(std::max(0.0F, value), 1.0F);
482 value = std::min(std::max(0.0F, value), 1.0F);
483 emit
sendToServer(QString(
"SET_GENERIC_PROGRESS 0 %1").arg(value));
499 value = std::min(std::max(0.0F, value), 1.0F);
501 QString().setNum(value));
509 emit
sendToServer(QString(
"SET_MUSIC_PLAYER_PROP SHUFFLE %1").arg(shuffle));
517 emit
sendToServer(QString(
"SET_MUSIC_PLAYER_PROP REPEAT %1").arg(repeat));
527 else if (value > 1.0F)
531 emit
sendToServer(
"SET_VOLUME_LEVEL " + QString().setNum(value));
553 aString =
"UPDATE_LEDS ";
554 aString += QString::number(mask);
564 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToTime");
574 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToMusic");
582 const QString &subtitle)
587 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToChannel");
600 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToMenu");
602 if (menuItems.isEmpty())
605 QString s =
"SWITCH_TO_MENU ";
608 s +=
' ' + QString(popMenu ?
"TRUE" :
"FALSE");
611 QListIterator<LCDMenuItem> it(menuItems);
623 s +=
" NOTCHECKABLE";
625 s +=
' ' + QString(curItem->
isSelected() ?
"TRUE" :
"FALSE");
626 s +=
' ' + QString(curItem->
Scroll() ?
"TRUE" :
"FALSE");
640 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToGeneric");
642 if (textItems.isEmpty())
645 QString s =
"SWITCH_TO_GENERIC";
647 QListIterator<LCDTextItem> it(textItems);
654 sRow.setNum(curItem->
getRow());
662 s +=
" ALIGN_CENTERED";
666 s +=
' ' + QString(curItem->
getScroll() ?
"TRUE" :
"FALSE");
677 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToVolume");
687 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"switchToNothing");
696 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"shutdown");
712 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"RESET");
721 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"An LCD device is being snuffed out of "
722 "existence (~LCD() was called)");
734 QString sRes = string;
735 sRes.replace(QString(
"\""), QString(
"\"\""));
736 sRes =
"\"" + sRes +
"\"";
void switchToChannel(const QString &channum="", const QString &title="", const QString &subtitle="")
void handleKeyPress(const QString &keyPressed)
void setTunerLEDs(enum LCDTunerSet tuner, bool on)
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
void setGenericBusy()
Update the generic screen to display a busy spinner.
void setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
void sendToServer(const QString &someText)
void setMusicShuffle(int shuffle)
Set music player's shuffle properties.
QRecursiveMutex m_socketLock
void setVideoFormatLEDs(enum LCDVideoFormatSet vcodec, bool on)
int(* m_getLEDMask)(void)
void switchToGeneric(QList< LCDTextItem > &textItems)
TEXT_ALIGNMENT getAlignment() const
void sendToServerSlot(const QString &someText)
QString getScreen() const
@ kMSRunShell
run process through shell
@ kMSRunBackground
run child in the background
static QString quotedString(const QString &string)
bool connectToHost(const QString &hostname, unsigned int port)
void setMusicRepeat(int repeat)
Set music player's repeat properties.
void setGenericProgress(float value)
Update the generic progress bar.
static void SetupLCD(void)
void setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on)
void switchToVolume(const QString &app_name)
void setupLEDs(int(*LedMaskFunc)(void))
QString GetAppBinDir(void)
void setVolumeLevel(float value)
void switchToMusic(const QString &artist, const QString &album, const QString &track)
void setFunctionLEDs(enum LCDFunctionSet func, bool on)
void setVariousLEDs(enum LCDVariousFlags various, bool on)
@ kMSDontDisableDrawing
avoid disabling UI drawing
static bool m_serverUnavailable
QString m_lcdShowMusicItems
void setMusicProgress(const QString &time, float value)
@ GENERIC_EXIT_RUNNING
Process is running.
unsigned int getRow() const
void setChannelProgress(const QString &time, float value)
void setAudioFormatLEDs(enum LCDAudioFormatSet acodec, bool on)
void switchToMenu(QList< LCDMenuItem > &menuItems, const QString &app_name="", bool popMenu=true)
static bool startLCDServer(void)