00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <qapplication.h>
00010 #include <qregexp.h>
00011 #include <unistd.h>
00012 #include <stdlib.h>
00013 #include <cmath>
00014
00015 #include "lcdprocclient.h"
00016 #include "mythcontext.h"
00017 #include "mythdialogs.h"
00018 #include "mythdbcon.h"
00019 #include "tv.h"
00020 #include "lcdserver.h"
00021 #include "lcddevice.h"
00022 #include "compat.h"
00023
00024 #define LCD_START_COL 3
00025
00026 #define LCD_VERSION_4 1
00027 #define LCD_VERSION_5 2
00028
00029 #define LCD_RECSTATUS_TIME 10000
00030 #define LCD_TIME_TIME 5000
00031 #define LCD_SCROLLLIST_TIME 2000
00032
00033 int lcdStartCol = LCD_START_COL;
00034
00035 LCDProcClient::LCDProcClient(LCDServer *lparent) :
00036 QObject(NULL, "LCDProcClient")
00037 {
00038
00039
00040
00041
00042
00043 if (debug_level > 0)
00044 VERBOSE(VB_GENERAL, "LCDProcClient: An LCDProcClient object now exists");
00045
00046 socket = new QSocket(this);
00047 connect(socket, SIGNAL(error(int)), this, SLOT(veryBadThings(int)));
00048 connect(socket, SIGNAL(readyRead()), this, SLOT(serverSendingData()));
00049
00050 m_parent = lparent;
00051
00052 lcd_ready = false;
00053
00054 lcdWidth = 5;
00055 lcdHeight = 1;
00056 cellWidth = 1;
00057 cellHeight = 1;
00058 lcdStartCol = LCD_START_COL;
00059 if (lcdWidth < 12)
00060 if (lcdHeight == 1)
00061 lcdStartCol = 0;
00062 else
00063 lcdStartCol = 1;
00064
00065 hostname = "";
00066 port = 13666;
00067
00068 timeFlash = false;
00069 scrollingText = "";
00070 progress = 0.0;
00071 generic_progress = 0.0;
00072 volume_level = 0.0;
00073 connected = false;
00074 send_buffer = "";
00075 lcdMenuItems = new QPtrList<LCDMenuItem>;
00076 lcdMenuItems->setAutoDelete(true);
00077
00078 lcdTextItems = new QPtrList<LCDTextItem>;
00079 lcdTextItems->setAutoDelete(true);
00080
00081 timeTimer = new QTimer(this);
00082 connect(timeTimer, SIGNAL(timeout()), this, SLOT(outputTime()));
00083
00084 scrollWTimer = new QTimer(this);
00085 connect(scrollWTimer, SIGNAL(timeout()), this, SLOT(scrollWidgets()));
00086
00087 preScrollWTimer = new QTimer(this);
00088 connect(preScrollWTimer, SIGNAL(timeout()), this,
00089 SLOT(beginScrollingWidgets()));
00090
00091 popMenuTimer = new QTimer(this);
00092 connect(popMenuTimer, SIGNAL(timeout()), this, SLOT(unPopMenu()));
00093
00094 menuScrollTimer = new QTimer(this);
00095 connect(menuScrollTimer, SIGNAL(timeout()), this, SLOT(scrollMenuText()));
00096
00097 menuPreScrollTimer = new QTimer(this);
00098 connect(menuPreScrollTimer, SIGNAL(timeout()), this,
00099 SLOT(beginScrollingMenuText()));
00100
00101 checkConnectionsTimer = new QTimer(this);
00102 connect(checkConnectionsTimer, SIGNAL(timeout()), this,
00103 SLOT(checkConnections()));
00104 checkConnectionsTimer->start(10000, false);
00105
00106 recStatusTimer = new QTimer(this);
00107 connect(recStatusTimer, SIGNAL(timeout()), this, SLOT(outputRecStatus()));
00108
00109 scrollListTimer = new QTimer(this);
00110 connect(scrollListTimer, SIGNAL(timeout()), this, SLOT(scrollList()));
00111
00112 showMessageTimer = new QTimer(this);
00113 connect(showMessageTimer, SIGNAL(timeout()), this,
00114 SLOT(removeStartupMessage()));
00115
00116 updateRecInfoTimer = new QTimer(this);
00117 connect(updateRecInfoTimer, SIGNAL(timeout()), this,
00118 SLOT(updateRecordingList()));
00119
00120 gContext->addListener(this);
00121
00122 isRecording = false;
00123 }
00124
00125 bool LCDProcClient::SetupLCD ()
00126 {
00127 QString lcd_host;
00128 int lcd_port;
00129
00130 lcd_host = gContext->GetSetting("LCDHost", "localhost");
00131 lcd_port = gContext->GetNumSetting("LCDPort", 13666);
00132
00133 if (lcd_host.length() > 0 && lcd_port > 1024)
00134 connectToHost(lcd_host, lcd_port);
00135
00136 return connected;
00137 }
00138
00139 bool LCDProcClient::connectToHost(const QString &lhostname, unsigned int lport)
00140 {
00141
00142
00143
00144 int timeout = 1000;
00145 hostname = lhostname;
00146 port = lport;
00147
00148
00149 if (!gContext->GetNumSetting("LCDEnable", 0))
00150 {
00151 connected = false;
00152 return connected;
00153 }
00154
00155 if (!connected)
00156 {
00157 QTextStream os(socket);
00158 socket->connectToHost(hostname, port);
00159
00160 while (--timeout && socket->state() != QSocket::Idle)
00161 {
00162 qApp->lock();
00163 qApp->processEvents();
00164 qApp->unlock();
00165 usleep(1000);
00166
00167 if (socket->state() == QSocket::Connected)
00168 {
00169 connected = true;
00170 os << "hello\n";
00171 break;
00172 }
00173 }
00174 }
00175
00176 return connected;
00177 }
00178
00179 void LCDProcClient::sendToServer(const QString &someText)
00180 {
00181
00182 if (socket->state() == QSocket::Idle)
00183 {
00184 if (!lcd_ready)
00185 return;
00186
00187 lcd_ready = false;
00188
00189
00190 stopAll();
00191
00192
00193
00194 VERBOSE(VB_IMPORTANT, "LCDProcClient: Connection to LCDd died unexpectedly.");
00195 return;
00196 }
00197
00198 QTextStream os(socket);
00199 os.setEncoding(QTextStream::Latin1);
00200
00201 last_command = someText;
00202
00203 if (connected)
00204 {
00205 if (debug_level > 9)
00206 VERBOSE(VB_NETWORK, "LCDProcClient: Sending to Server: " << someText);
00207
00208
00209
00210 os << someText << "\n";
00211 }
00212 else
00213 {
00214
00215
00216 send_buffer += someText;
00217 send_buffer += "\n";
00218 }
00219 }
00220
00221 void LCDProcClient::setPriority(const QString &screen, PRIORITY priority)
00222 {
00223 QString aString;
00224 int err = 0;
00225 aString = "screen_set ";
00226 aString += screen;
00227 aString += " priority ";
00228
00229 switch (priority) {
00230 case TOP:
00231 aString += prioTop;
00232 break;
00233 case URGENT:
00234 aString += prioUrgent;
00235 break;
00236 case HIGH:
00237 aString += prioHigh;
00238 break;
00239 case MEDIUM:
00240 aString += prioMedium;
00241 break;
00242 case LOW:
00243 aString += prioLow;
00244 break;
00245 case OFF:
00246 aString += prioOff;
00247 break;
00248 default:
00249 err = 1;
00250 break;
00251 }
00252 if (err == 0)
00253 sendToServer (aString);
00254 }
00255
00256 void LCDProcClient::setHeartbeat (const QString &screen, bool onoff)
00257 {
00258 QString msg;
00259 if (onoff)
00260 {
00261 if (pVersion == LCD_VERSION_4)
00262 {
00263 msg = "widget_add " + screen + " heartbeat";
00264 }
00265 if (pVersion == LCD_VERSION_5)
00266 {
00267 msg = "screen_set " + screen + " heartbeat on";
00268 }
00269 }
00270 else
00271 {
00272 if (pVersion == LCD_VERSION_4)
00273 {
00274 msg = "widget_del " + screen + " heartbeat";
00275 }
00276 if (pVersion == LCD_VERSION_5)
00277 {
00278 msg = "screen_set " + screen + " heartbeat off";
00279 }
00280 }
00281 sendToServer (msg);
00282 }
00283
00284 void LCDProcClient::checkConnections()
00285 {
00286 if (debug_level > 0)
00287 VERBOSE(VB_GENERAL, "LCDProcClient: checking connections");
00288
00289
00290 if (!gContext->IsConnectedToMaster())
00291 {
00292 if (debug_level > 0)
00293 VERBOSE(VB_GENERAL, "LCDProcClient: connecting to master server");
00294 gContext->ConnectToMasterServer(false);
00295 }
00296
00297
00298 if (socket->state() == QSocket::Idle)
00299 {
00300 if (debug_level > 0)
00301 VERBOSE(VB_GENERAL, "LCDProcClient: connecting to LCDProc server");
00302
00303 lcd_ready = false;
00304 connected = false;
00305
00306
00307 connectToHost(hostname, port);
00308 }
00309 }
00310
00311 void LCDProcClient::serverSendingData()
00312 {
00313 QString lineFromServer, tempString;
00314 QStringList aList;
00315 QStringList::Iterator it;
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 while(socket->canReadLine())
00328 {
00329 lineFromServer = socket->readLine();
00330 lineFromServer = lineFromServer.replace( QRegExp("\n"), "" );
00331 lineFromServer = lineFromServer.replace( QRegExp("\r"), "" );
00332
00333 if (debug_level > 0)
00334
00335 if (lineFromServer != "success")
00336 VERBOSE(VB_NETWORK, "LCDProcClient: Received from server: "
00337 << lineFromServer);
00338
00339 aList = QStringList::split(" ", lineFromServer);
00340 if (aList.first() == "connect")
00341 {
00342
00343
00344
00345
00346 it = aList.begin();
00347 it++;
00348 if ((*it) != "LCDproc")
00349 {
00350 VERBOSE(VB_IMPORTANT, "LCDProcClient: WARNING: Second parameter "
00351 "returned from LCDd was not \"LCDproc\"");
00352 }
00353
00354
00355 it++;
00356 QString server_version = *it;
00357 it++;
00358 it++;
00359 QString protocol_version = *it;
00360 setVersion (server_version, protocol_version);
00361 it++;
00362 it++;
00363 it++;
00364
00365 tempString = *it;
00366 setWidth(tempString.toInt());
00367
00368 it++;
00369 it++;
00370
00371 tempString = *it;
00372 setHeight(tempString.toInt());
00373 it++;
00374 it++;
00375
00376 tempString = *it;
00377 setCellWidth(tempString.toInt());
00378
00379 it++;
00380 it++;
00381
00382 tempString = *it;
00383 setCellHeight(tempString.toInt());
00384
00385 init();
00386
00387 describeServer();
00388 }
00389
00390 if (aList.first() == "huh?")
00391 {
00392 VERBOSE(VB_IMPORTANT, "LCDProcClient: WARNING: Something is getting"
00393 "passed to LCDd that it doesn't understand");
00394 VERBOSE(VB_IMPORTANT, "last command: " << last_command);
00395 }
00396 else if (aList.first() == "key")
00397 {
00398 if (m_parent)
00399 m_parent->sendKeyPress(aList.last().stripWhiteSpace());
00400 }
00401 }
00402 }
00403
00404 void LCDProcClient::init()
00405 {
00406 QString aString;
00407 lcd_keystring = "";
00408
00409 connected = TRUE;
00410
00411
00412
00413 sendToServer("client_set name Myth");
00414
00415
00416
00417
00418 sendToServer("screen_add Time");
00419 setPriority("Time", MEDIUM);
00420
00421 if (gContext->GetSetting("LCDBigClock", "1") == "1")
00422 {
00423
00424 sendToServer("widget_add Time d0 num");
00425 sendToServer("widget_add Time d1 num");
00426 sendToServer("widget_add Time sep num");
00427 sendToServer("widget_add Time d2 num");
00428 sendToServer("widget_add Time d3 num");
00429 dobigclock(1);
00430 }
00431 else
00432 {
00433 sendToServer("widget_add Time timeWidget string");
00434 sendToServer("widget_add Time topWidget string");
00435 }
00436
00437
00438
00439
00440 sendToServer("screen_add Menu");
00441 setPriority("Menu", LOW);
00442 sendToServer("widget_add Menu topWidget string");
00443 for (unsigned int i = 1; i <= lcdHeight; i++)
00444 {
00445 aString = "widget_add Menu menuWidget";
00446 aString += QString::number (i);
00447 aString += " string";
00448 sendToServer(aString);
00449 }
00450
00451
00452 sendToServer("screen_add Music");
00453 setPriority("Music", LOW);
00454 sendToServer("widget_add Music topWidget1 string");
00455 sendToServer("widget_add Music topWidget2 string");
00456 sendToServer("widget_add Music timeWidget string");
00457 sendToServer("widget_add Music infoWidget string");
00458 sendToServer("widget_add Music progressBar hbar");
00459
00460
00461 sendToServer("screen_add Channel");
00462 setPriority("Channel", LOW);
00463 sendToServer("widget_add Channel topWidget string");
00464 sendToServer("widget_add Channel botWidget string");
00465 sendToServer("widget_add Channel progressBar hbar");
00466
00467
00468 sendToServer("screen_add Generic");
00469 setPriority("Generic", LOW);
00470 sendToServer("widget_add Generic textWidget1 string");
00471 sendToServer("widget_add Generic textWidget2 string");
00472 sendToServer("widget_add Generic textWidget3 string");
00473 sendToServer("widget_add Generic textWidget4 string");
00474 sendToServer("widget_add Generic progressBar hbar");
00475
00476
00477 sendToServer("screen_add Volume");
00478 setPriority("Volume", LOW);
00479 sendToServer("widget_add Volume topWidget string");
00480 sendToServer("widget_add Volume botWidget string");
00481 sendToServer("widget_add Volume progressBar hbar");
00482
00483
00484 sendToServer("screen_add RecStatus");
00485 setPriority("RecStatus", LOW);
00486 sendToServer("widget_add RecStatus textWidget1 string");
00487 sendToServer("widget_add RecStatus textWidget2 string");
00488 sendToServer("widget_add RecStatus textWidget3 string");
00489 sendToServer("widget_add RecStatus progressBar hbar");
00490
00491 lcd_ready = true;
00492 loadSettings();
00493
00494
00495 switchToTime();
00496
00497 updateRecordingList();
00498
00499
00500 if (startup_message != "")
00501 showStartupMessage();
00502
00503
00504 if (send_buffer.length() > 0)
00505 {
00506 sendToServer(send_buffer);
00507 send_buffer = "";
00508 }
00509 }
00510
00511 QString LCDProcClient::expandString(const QString &aString)
00512 {
00513 if (pVersion != LCD_VERSION_5)
00514 return aString;
00515
00516 QString bString;
00517
00518
00519 for (uint x = 0; x < aString.length(); x++)
00520 {
00521 bString += aString.at(x) + QString(" ");
00522 }
00523
00524 return bString;
00525 }
00526
00527 void LCDProcClient::loadSettings()
00528 {
00529 if (!lcd_ready)
00530 return;
00531
00532 QString aString;
00533 QString old_keystring = lcd_keystring;
00534
00535 timeformat = gContext->GetSetting("TimeFormat", "h:mm AP");
00536
00537
00538 lcd_showmusic=(gContext->GetSetting("LCDShowMusic", "1")=="1");
00539 lcd_showmusic_items=(gContext->GetSetting("LCDShowMusicItems", "ArtistAlbumTitle"));
00540 lcd_showtime=(gContext->GetSetting("LCDShowTime", "1")=="1");
00541 lcd_showchannel=(gContext->GetSetting("LCDShowChannel", "1")=="1");
00542 lcd_showgeneric=(gContext->GetSetting("LCDShowGeneric", "1")=="1");
00543 lcd_showvolume=(gContext->GetSetting("LCDShowVolume", "1")=="1");
00544 lcd_showmenu=(gContext->GetSetting("LCDShowMenu", "1")=="1");
00545 lcd_showrecstatus=(gContext->GetSetting("LCDShowRecStatus", "1")=="1");
00546 lcd_backlighton=(gContext->GetSetting("LCDBacklightOn", "1")=="1");
00547 lcd_heartbeaton=(gContext->GetSetting("LCDHeartBeatOn", "1")=="1");
00548 aString = gContext->GetSetting("LCDPopupTime", "5");
00549 lcd_popuptime = aString.toInt() * 1000;
00550 lcd_bigclock = (gContext->GetSetting("LCDBigClock", "1")=="1");
00551 lcd_keystring = gContext->GetSetting("LCDKeyString", "ABCDEF");
00552
00553 if (old_keystring != "")
00554 {
00555 aString = "client_del_key " + expandString(old_keystring);
00556 sendToServer(aString);
00557 }
00558
00559 aString = "client_add_key " + expandString(lcd_keystring);
00560 sendToServer(aString);
00561
00562 setHeartbeat ("Time", lcd_heartbeaton);
00563 if (lcd_backlighton)
00564 sendToServer("screen_set Time backlight on");
00565 else
00566 sendToServer("screen_set Time backlight off");
00567
00568 setHeartbeat ("Menu", lcd_heartbeaton);
00569 sendToServer("screen_set Menu backlight on");
00570
00571 setHeartbeat ("Music", lcd_heartbeaton);
00572 sendToServer("screen_set Music backlight on");
00573
00574 setHeartbeat ("Channel", lcd_heartbeaton);
00575 sendToServer("screen_set Channel backlight on");
00576
00577 setHeartbeat ("Generic", lcd_heartbeaton);
00578 sendToServer("screen_set Generic backlight on");
00579
00580 setHeartbeat ("Volume", lcd_heartbeaton);
00581 sendToServer("screen_set Volume backlight on");
00582
00583 setHeartbeat ("RecStatus", lcd_heartbeaton);
00584 sendToServer("screen_set RecStatus backlight on");
00585 }
00586
00587 void LCDProcClient::showStartupMessage(void)
00588 {
00589 QPtrList<LCDTextItem> textItems;
00590 textItems.setAutoDelete(true);
00591
00592 QStringList list = formatScrollerText(startup_message);
00593
00594 int startrow = 1;
00595 if (list.count() < lcdHeight)
00596 startrow = ((lcdHeight - list.count()) / 2) + 1;
00597
00598 for (uint x = 0; x < list.count(); x++)
00599 {
00600 if (x == lcdHeight)
00601 break;
00602 textItems.append(new LCDTextItem(x + startrow, ALIGN_LEFT, list[x],
00603 "Generic", false));
00604 }
00605
00606 switchToGeneric(&textItems);
00607
00608 showMessageTimer->start(startup_showtime * 1000, true);
00609 }
00610
00611 void LCDProcClient::removeStartupMessage(void)
00612 {
00613 switchToTime();
00614 }
00615
00616 void LCDProcClient::setStartupMessage(QString msg, uint messagetime)
00617 {
00618 startup_message = msg;
00619 startup_showtime = messagetime;
00620 }
00621
00622 void LCDProcClient::setWidth(unsigned int x)
00623 {
00624 if (x < 1 || x > 80)
00625 return;
00626 else
00627 lcdWidth = x;
00628 }
00629
00630 void LCDProcClient::setHeight(unsigned int x)
00631 {
00632 if (x < 1 || x > 80)
00633 return;
00634 else
00635 lcdHeight = x;
00636 }
00637
00638 void LCDProcClient::setCellWidth(unsigned int x)
00639 {
00640 if (x < 1 || x > 16)
00641 return;
00642 else
00643 cellWidth = x;
00644 }
00645
00646 void LCDProcClient::setCellHeight(unsigned int x)
00647 {
00648 if (x < 1 || x > 16)
00649 return;
00650 else
00651 cellHeight = x;
00652 }
00653
00654 void LCDProcClient::setVersion(const QString &sversion, const QString &pversion)
00655 {
00656 protocolVersion = pversion;
00657 serverVersion = sversion;
00658
00659
00660
00661
00662 if (serverVersion.startsWith ("CVS-current") ||
00663 serverVersion.startsWith ("0.5"))
00664 {
00665
00666 pVersion = LCD_VERSION_5;
00667 prioTop = "input";
00668 prioUrgent = "alert";
00669 prioHigh = "foreground";
00670 prioMedium = "info";
00671 prioLow = "background";
00672 prioOff = "hidden";
00673 }
00674 else
00675 {
00676 pVersion = LCD_VERSION_4;
00677 prioTop = "64";
00678 prioUrgent = "128";
00679 prioHigh = "240";
00680 prioMedium = "248";
00681 prioLow = "252";
00682 prioOff = "255";
00683 }
00684 }
00685
00686 void LCDProcClient::describeServer()
00687 {
00688 if (debug_level > 0)
00689 {
00690 VERBOSE(VB_GENERAL,
00691 QString("LCDProcClient: The server is %1x%2 with each cell being %3x%4." )
00692 .arg(lcdWidth).arg(lcdHeight).arg(cellWidth).arg(cellHeight));
00693 VERBOSE(VB_GENERAL,
00694 QString("LCDProcClient: LCDd version %1, protocol version %2.")
00695 .arg(serverVersion).arg(protocolVersion));
00696 }
00697
00698 if (debug_level > 1)
00699 {
00700 VERBOSE(VB_GENERAL, QString("LCDProcClient: MythTV LCD settings:"));
00701 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showmusic : %1")
00702 .arg(lcd_showmusic));
00703 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showmusicitems : %1")
00704 .arg(lcd_showmusic_items));
00705 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showtime : %1")
00706 .arg(lcd_showtime));
00707 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showchannel : %1")
00708 .arg(lcd_showchannel));
00709 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showrecstatus : %1")
00710 .arg(lcd_showrecstatus));
00711 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showgeneric : %1")
00712 .arg(lcd_showgeneric));
00713 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showvolume : %1")
00714 .arg(lcd_showvolume));
00715 VERBOSE(VB_GENERAL, QString("LCDProcClient: - showmenu : %1")
00716 .arg(lcd_showmenu));
00717 VERBOSE(VB_GENERAL, QString("LCDProcClient: - backlighton : %1")
00718 .arg(lcd_backlighton));
00719 VERBOSE(VB_GENERAL, QString("LCDProcClient: - heartbeaton : %1")
00720 .arg(lcd_heartbeaton));
00721 VERBOSE(VB_GENERAL, QString("LCDProcClient: - popuptime : %1")
00722 .arg(lcd_popuptime));
00723 }
00724 }
00725
00726 void LCDProcClient::veryBadThings(int anError)
00727 {
00728
00729
00730 QString err;
00731
00732 if (anError == QSocket::ErrConnectionRefused)
00733 err = "connection refused.";
00734 else if (anError == QSocket::ErrHostNotFound)
00735 err = "host not found.";
00736 else if (anError == QSocket::ErrSocketRead)
00737 err = "socket read failed.";
00738 else
00739 err = "unknown error.";
00740
00741 VERBOSE(VB_IMPORTANT, QString("Could not connect to LCDd: %1").arg(err));
00742 socket->clearPendingData();
00743 socket->close();
00744 }
00745
00746 void LCDProcClient::scrollList()
00747 {
00748 if (scrollListItems.count() == 0)
00749 return;
00750
00751 if (activeScreen != scrollListScreen)
00752 return;
00753
00754 outputLeftText(scrollListScreen, scrollListItems[scrollListItem],
00755 scrollListWidget, scrollListRow);
00756
00757 scrollListItem++;
00758 if (scrollListItem >= scrollListItems.count())
00759 scrollListItem = 0;
00760 }
00761
00762 void LCDProcClient::stopAll()
00763 {
00764
00765
00766
00767 if (debug_level > 1)
00768 VERBOSE(VB_GENERAL, "LCDProcClient: stopAll");
00769
00770 if (lcd_ready)
00771 {
00772 setPriority("Time", OFF);
00773 setPriority("Music", OFF);
00774 setPriority("Channel", OFF);
00775 setPriority("Generic", OFF);
00776 setPriority("Volume", OFF);
00777 setPriority("Menu", OFF);
00778 setPriority("RecStatus", OFF);
00779 }
00780
00781 timeTimer->stop();
00782 preScrollWTimer->stop();
00783 scrollWTimer->stop();
00784 popMenuTimer->stop();
00785 menuScrollTimer->stop();
00786 menuPreScrollTimer->stop();
00787 recStatusTimer->stop();
00788 scrollListTimer->stop();
00789
00790 unPopMenu();
00791 }
00792
00793 void LCDProcClient::startTime()
00794 {
00795 setPriority("Time", MEDIUM);
00796 setPriority("RecStatus", LOW);
00797
00798 timeTimer->start(1000, FALSE);
00799 outputTime();
00800 activeScreen = "Time";
00801 isTimeVisible = true;
00802
00803 if (lcd_showrecstatus && isRecording)
00804 recStatusTimer->start(LCD_TIME_TIME, FALSE);
00805 }
00806
00807 void LCDProcClient::outputText(QPtrList<LCDTextItem> *textItems)
00808 {
00809 if (!lcd_ready)
00810 return;
00811
00812 QPtrListIterator<LCDTextItem> it( *textItems );
00813 LCDTextItem *curItem;
00814 QString num;
00815 unsigned int counter = 1;
00816
00817
00818
00819
00820 while ((curItem = it.current()) != 0 && counter < lcdHeight)
00821 {
00822 ++it;
00823 num.setNum(curItem->getRow());
00824
00825 if (curItem->getScroll())
00826 assignScrollingWidgets(curItem->getText(), curItem->getScreen(),
00827 "textWidget" + num, curItem->getRow());
00828 else
00829 {
00830 switch (curItem->getAlignment())
00831 {
00832 case ALIGN_LEFT:
00833 outputLeftText(curItem->getScreen(), curItem->getText(),
00834 "textWidget" + num, curItem->getRow());
00835 break;
00836 case ALIGN_RIGHT:
00837 outputRightText(curItem->getScreen(), curItem->getText(),
00838 "textWidget" + num, curItem->getRow());
00839 break;
00840 case ALIGN_CENTERED:
00841 outputCenteredText(curItem->getScreen(), curItem->getText(),
00842 "textWidget" + num, curItem->getRow());
00843 break;
00844 default: break;
00845 }
00846 }
00847
00848 ++counter;
00849 }
00850 }
00851
00852 void LCDProcClient::outputCenteredText(QString theScreen, QString theText, QString widget,
00853 int row)
00854 {
00855 QString aString;
00856 unsigned int x = 0;
00857
00858 x = (lcdWidth - theText.length()) / 2 + 1;
00859
00860 if (x > lcdWidth)
00861 x = 1;
00862
00863 aString = "widget_set ";
00864 aString += theScreen;
00865 aString += " " + widget + " ";
00866 aString += QString::number(x);
00867 aString += " ";
00868 aString += QString::number(row);
00869 aString += " \"";
00870 aString += theText.replace ('"', "\"");
00871 aString += "\"";
00872 sendToServer(aString);
00873 }
00874
00875 void LCDProcClient::outputLeftText(QString theScreen, QString theText, QString widget,
00876 int row)
00877 {
00878 QString aString;
00879 aString = "widget_set ";
00880 aString += theScreen;
00881 aString += " " + widget + " 1 ";
00882 aString += QString::number(row);
00883 aString += " \"";
00884 aString += theText.replace ('"', "\"");
00885 aString += "\"";
00886 sendToServer(aString);
00887 }
00888
00889 void LCDProcClient::outputRightText(QString theScreen, QString theText, QString widget,
00890 int row)
00891 {
00892 QString aString;
00893 unsigned int x;
00894
00895 x = (int)(lcdWidth - theText.length()) + 1;
00896
00897 aString = "widget_set ";
00898 aString += theScreen;
00899 aString += " " + widget + " ";
00900 aString += QString::number(x);
00901 aString += " ";
00902 aString += QString::number(row);
00903 aString += " \"";
00904 aString += theText.replace ('"', "\"");
00905 aString += "\"";
00906 sendToServer(aString);
00907 }
00908
00909 void LCDProcClient::assignScrollingList(QStringList theList, QString theScreen,
00910 QString theWidget, int theRow)
00911 {
00912 scrollListScreen = theScreen;
00913 scrollListWidget = theWidget;
00914 scrollListRow = theRow;
00915 scrollListItems = theList;
00916
00917 scrollListItem = 0;
00918 scrollList();
00919 scrollListTimer->start(LCD_SCROLLLIST_TIME, FALSE);
00920 }
00921
00922
00923
00924
00925
00926
00927
00928
00929 void LCDProcClient::assignScrollingWidgets(QString theText, QString theScreen,
00930 QString theWidget, int theRow)
00931 {
00932 scrollScreen = theScreen;
00933
00934
00935 lcdTextItems->append(new LCDTextItem(theRow, ALIGN_LEFT, theText,
00936 theScreen, true, theWidget));
00937 }
00938
00939 void LCDProcClient::formatScrollingWidgets()
00940 {
00941
00942 scrollWTimer->stop();
00943 preScrollWTimer->stop();
00944
00945 if (lcdTextItems->isEmpty())
00946 return;
00947
00948 unsigned int max_len = 0;
00949 QPtrListIterator<LCDTextItem> it(*lcdTextItems);
00950 LCDTextItem *curItem;
00951
00952
00953 for(; (curItem = it.current()) != 0; ++it)
00954 {
00955 if (curItem->getText().length() > max_len)
00956 max_len = curItem->getText().length();
00957 }
00958
00959
00960 it.toFirst();
00961 while ((curItem = it.current()) != 0)
00962 {
00963 ++it;
00964 if (curItem->getText().length() > lcdWidth)
00965 {
00966 QString temp, temp2;
00967 temp = temp.fill(QChar(' '), max_len - curItem->getText().length());
00968 temp2 = temp2.fill(QChar(' '), lcdWidth);
00969 curItem->setText(temp2 + curItem->getText() + temp);
00970 outputLeftText(scrollScreen,
00971 curItem->getText().mid(lcdWidth, max_len),
00972 curItem->getWidget(), curItem->getRow());
00973 }
00974 else
00975 {
00976 curItem->setScrollable(false);
00977 outputCenteredText(scrollScreen, curItem->getText(),
00978 curItem->getWidget(), curItem->getRow());
00979 }
00980 }
00981
00982 if (max_len <= lcdWidth)
00983
00984 return;
00985
00986 preScrollWTimer->start(2000, TRUE);
00987 }
00988
00989 void LCDProcClient::beginScrollingWidgets()
00990 {
00991 scrollPosition = lcdWidth;
00992 preScrollWTimer->stop();
00993 scrollWTimer->start(400, false);
00994 }
00995
00996 void LCDProcClient::scrollWidgets()
00997 {
00998 if (activeScreen != scrollScreen)
00999 return;
01000
01001 if (lcdTextItems->isEmpty())
01002 return;
01003
01004 QPtrListIterator<LCDTextItem> it(*lcdTextItems);
01005 LCDTextItem *curItem;
01006
01007 unsigned int len = 0;
01008 for(; (curItem = it.current()) != 0; ++it)
01009 {
01010 if (curItem->getScroll())
01011 {
01012
01013 len = curItem->getText().length();
01014
01015 outputLeftText(scrollScreen,
01016 curItem->getText().mid(scrollPosition, lcdWidth),
01017 curItem->getWidget(), curItem->getRow());
01018 }
01019 }
01020 if (len == 0)
01021 {
01022
01023 cerr << "LCDProcClient::scrollWidgets called without scrollable items"
01024 << endl;
01025 scrollWTimer->stop();
01026 return;
01027 }
01028 scrollPosition++;
01029 if (scrollPosition >= len)
01030 scrollPosition = lcdWidth;
01031 }
01032
01033 void LCDProcClient::startMusic(QString artist, QString album, QString track)
01034 {
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053 sendToServer("widget_set Music progressBar 1 1 0");
01054 sendToServer("widget_set Music timeWidget 1 1 \"\"");
01055 lcdTextItems->clear();
01056
01057 QString aString;
01058 music_progress = 0.0f;
01059 aString = artist;
01060 if (lcd_showmusic_items == "ArtistAlbumTitle")
01061 {
01062 aString += " [";
01063 aString += album;
01064 aString += "] ";
01065 }
01066 else if (lcdHeight < 4)
01067 {
01068 aString += " - ";
01069 }
01070
01071 if (lcdHeight < 4)
01072 {
01073 aString += track;
01074 }
01075 else
01076 {
01077 assignScrollingWidgets(track, "Music", "topWidget2", 2);
01078 }
01079 assignScrollingWidgets(aString, "Music", "topWidget1", 1);
01080 formatScrollingWidgets();
01081
01082
01083
01084 activeScreen = "Music";
01085 if (lcd_showmusic)
01086 setPriority("Music", HIGH);
01087 }
01088
01089 void LCDProcClient::startChannel(QString channum, QString title, QString subtitle)
01090 {
01091 QString aString;
01092
01093 if (lcd_showchannel)
01094 setPriority("Channel", HIGH);
01095
01096 activeScreen = "Channel";
01097
01098 if (lcdHeight <= 2)
01099 {
01100 aString = channum + "|" + title;
01101 if (!subtitle.isEmpty())
01102 aString += "|" + subtitle;
01103 QStringList list = formatScrollerText(aString);
01104 assignScrollingList(list, "Channel", "topWidget", 1);
01105 }
01106 else
01107 {
01108 aString = channum;
01109 lcdTextItems->clear();
01110 assignScrollingWidgets(aString, "Channel", "topWidget", 1);
01111 aString = title;
01112 if (subtitle.length() > 0)
01113 {
01114 aString += " - '";
01115 aString += subtitle;
01116 aString += "'";
01117 }
01118 assignScrollingWidgets(aString, "Channel", "botWidget", 2);
01119 formatScrollingWidgets();
01120 }
01121
01122 progress = 0.0;
01123 outputChannel();
01124 }
01125
01126 void LCDProcClient::startGeneric(QPtrList<LCDTextItem> * textItems)
01127 {
01128 LCDTextItem *curItem;
01129 QPtrListIterator<LCDTextItem> it( *textItems );
01130 QString aString;
01131
01132 if (lcd_showgeneric)
01133 setPriority("Generic", TOP);
01134
01135
01136
01137 outputLeftText("Generic", "", "textWidget1", 1);
01138 outputLeftText("Generic", "", "textWidget2", 2);
01139 outputLeftText("Generic", "", "textWidget3", 3);
01140
01141
01142 if (textItems->isEmpty())
01143 return;
01144
01145 activeScreen = "Generic";
01146
01147 busy_progress = false;
01148 busy_pos = 1;
01149 busy_direction = 1;
01150 busy_indicator_size = 2.0f;
01151 generic_progress = 0.0;
01152
01153
01154 if ((curItem = it.current()) == 0)
01155 return;
01156
01157
01158 ++it;
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168 lcdTextItems->clear();
01169 assignScrollingWidgets(curItem->getText(), "Generic", "textWidget1",
01170 curItem->getRow());
01171
01172 outputGeneric();
01173
01174
01175 if (textItems->removeFirst() != 0)
01176 outputText(textItems);
01177 formatScrollingWidgets();
01178 }
01179
01180 void LCDProcClient::startMenu(QPtrList<LCDMenuItem> *menuItems, QString app_name,
01181 bool popMenu)
01182 {
01183
01184 if (menuItems->isEmpty())
01185 return;
01186
01187 QString aString;
01188
01189
01190 menuScrollTimer->stop();
01191
01192
01193 if (lcd_showmenu)
01194 setPriority("Menu", URGENT);
01195
01196
01197 if (lcdHeight > 1)
01198 outputCenteredText("Menu", app_name, "topWidget", 1);
01199
01200 QPtrListIterator<LCDMenuItem> it(*menuItems);
01201 LCDMenuItem *curItem;
01202
01203
01204
01205 unsigned int selectedItem = 0;
01206 unsigned int counter = 0;
01207 bool oneSelected = false;
01208
01209 while ((curItem = it.current()) != 0)
01210 {
01211 ++it;
01212 if (curItem->isSelected() && !oneSelected)
01213 {
01214 selectedItem = counter + 1;
01215 oneSelected = true;
01216 break;
01217 }
01218 ++counter;
01219 }
01220
01221
01222 if (!oneSelected)
01223 {
01224 sendToServer("widget_set Menu topWidget 1 1 \"No menu item selected\"");
01225 sendToServer("widget_set Menu menuWidget1 1 2 \" ABORTING \"");
01226 menuScrollTimer->stop();
01227 return;
01228 }
01229
01230 popMenuTimer->stop();
01231
01232 if (popMenu)
01233 popMenuTimer->start(lcd_popuptime, true);
01234
01235
01236
01237 QPtrListIterator<LCDMenuItem> itTemp(*menuItems);
01238 lcdMenuItems->clear();
01239 counter = 1;
01240 while ((curItem = itTemp.current()) != 0)
01241 {
01242 ++itTemp;
01243 lcdMenuItems->append(new LCDMenuItem(curItem->isSelected(),
01244 curItem->isChecked(), curItem->ItemName(),
01245 curItem->getIndent()));
01246 ++counter;
01247 }
01248
01249
01250
01251 if (lcdHeight <= 2)
01252 {
01253 it.toFirst();
01254 while ((curItem = it.current()) != 0)
01255 {
01256 ++it;
01257 if (curItem->isSelected())
01258 {
01259
01260 if (curItem->ItemName().length() > (lcdWidth - lcdStartCol))
01261 {
01262 menuPreScrollTimer->start(2000, true);
01263 curItem->setScroll(true);
01264 }
01265 else
01266 {
01267 menuPreScrollTimer->stop();
01268 curItem->setScroll(false);
01269 }
01270 if (lcdHeight == 2)
01271 {
01272 aString = "widget_set Menu menuWidget1 1 2 \">";
01273 }
01274 else
01275 {
01276 aString = "widget_set Menu menuWidget1 1 1 \"";
01277 }
01278
01279 if (lcdStartCol == 1)
01280 {
01281 switch (curItem->isChecked())
01282 {
01283 case CHECKED: aString += "X "; break;
01284 case UNCHECKED: aString += "O "; break;
01285 case NOTCHECKABLE: aString += " "; break;
01286 default: break;
01287 }
01288 }
01289 else if (lcdStartCol != 0)
01290 {
01291 switch (curItem->isChecked())
01292 {
01293 case CHECKED: aString += "X "; break;
01294 case UNCHECKED: aString += "O "; break;
01295 case NOTCHECKABLE: aString += " "; break;
01296 default: break;
01297 }
01298 }
01299
01300 aString += curItem->ItemName().left(lcdWidth - lcdStartCol) +
01301 "\"";
01302 sendToServer(aString);
01303 return;
01304 }
01305 }
01306
01307 return;
01308 }
01309
01310
01311 counter = 1;
01312 curItem = it.toFirst();
01313
01314
01315 unsigned int midPoint = (lcdHeight/2) - 1;
01316 if (selectedItem > midPoint && it.count() >= lcdHeight-1)
01317 {
01318 while (counter != selectedItem)
01319 {
01320 ++it;
01321 ++counter;
01322 }
01323 it -= midPoint;
01324 counter -= midPoint;
01325 }
01326
01327
01328
01329 if (counter + midPoint > it.count() - midPoint && counter > midPoint)
01330 {
01331 it -= (counter+(lcdHeight/2)- 1) - (it.count () - midPoint);
01332 }
01333
01334 counter = 1;
01335 while ((curItem = it.current()) != 0)
01336 {
01337
01338 if ((counter + 1) > lcdHeight)
01339 break;
01340
01341 ++it;
01342
01343 aString = "widget_set Menu menuWidget";
01344 aString += QString::number(counter) + " 1 ";
01345 aString += QString::number(counter + 1) + " \"";
01346
01347 if (curItem->isSelected())
01348 aString += ">";
01349 else
01350 aString += " ";
01351
01352 switch (curItem->isChecked())
01353 {
01354 case CHECKED: aString += "X "; break;
01355 case UNCHECKED: aString += "O "; break;
01356 case NOTCHECKABLE: aString += " "; break;
01357 default: break;
01358 }
01359
01360 aString += curItem->ItemName().left(lcdWidth - lcdStartCol) + "\"";
01361 sendToServer(aString);
01362
01363 ++counter;
01364 }
01365
01366
01367 while (counter < lcdHeight)
01368 {
01369 aString = "widget_set Menu menuWidget";
01370 aString += QString::number(counter) + " 1 ";
01371 aString += QString::number(counter + 1) + " \"\"";
01372 sendToServer(aString);
01373
01374 ++counter;
01375 }
01376
01377 menuPreScrollTimer->start(2000, true);
01378 }
01379
01380 void LCDProcClient::beginScrollingMenuText()
01381 {
01382
01383
01384
01385 if (!lcdMenuItems)
01386 return;
01387
01388 menuScrollPosition = 1;
01389
01390 QPtrListIterator<LCDMenuItem> it( *lcdMenuItems );
01391 LCDMenuItem *curItem;
01392
01393 QString temp;
01394
01395
01396 while ((curItem = it.current()) != 0)
01397 {
01398 ++it;
01399
01400
01401 if (curItem->ItemName().length() > (lcdWidth - lcdStartCol))
01402 {
01403 temp = temp.fill(QChar(' '), lcdWidth - curItem->getIndent() -
01404 lcdStartCol);
01405 curItem->setItemName(temp + curItem->ItemName());
01406 curItem->setScrollPos(curItem->getIndent() + temp.length());
01407 curItem->setScroll(true);
01408 }
01409 else
01410 curItem->setScroll(false);
01411 }
01412
01413
01414 menuScrollTimer->stop();
01415 menuScrollTimer->start(250, FALSE);
01416 }
01417
01418 void LCDProcClient::scrollMenuText()
01419 {
01420 if (!lcdMenuItems)
01421 return;
01422
01423 QString aString, bString;
01424 QPtrListIterator<LCDMenuItem> it(*lcdMenuItems);
01425 LCDMenuItem *curItem;
01426
01427 ++menuScrollPosition;
01428
01429
01430
01431 unsigned int selectedItem = 0;
01432 unsigned int counter = 0;
01433 bool oneSelected = false;
01434
01435 while ((curItem = it.current()) != 0)
01436 {
01437 ++it;
01438 if (curItem->isSelected() && !oneSelected)
01439 {
01440 selectedItem = counter + 1;
01441 oneSelected = true;
01442 break;
01443 }
01444 ++counter;
01445 }
01446
01447
01448
01449 curItem = it.toFirst();
01450 if (lcdHeight <= 2)
01451 {
01452 it.toFirst();
01453 while ((curItem = it.current()) != 0)
01454 {
01455 ++it;
01456 if (curItem->isSelected())
01457 {
01458 curItem->incrementScrollPos();
01459 if (curItem->getScrollPos() > curItem->ItemName().length())
01460 {
01461
01462 menuScrollTimer->stop();
01463 menuScrollTimer->start(500, FALSE);
01464 curItem->setScrollPos(curItem->getIndent());
01465 }
01466
01467
01468
01469
01470 if (curItem->ItemName().length() < (lcdWidth - lcdStartCol))
01471 menuScrollTimer->stop();
01472
01473 if (lcdHeight == 2)
01474 {
01475 aString = "widget_set Menu menuWidget1 1 2 \">";
01476 }
01477 else
01478 {
01479 aString = "widget_set Menu menuWidget1 1 1 \"";
01480 }
01481
01482 if (lcdWidth < 12)
01483 {
01484 switch(curItem->isChecked())
01485 {
01486 case CHECKED: aString += "X"; break;
01487 case UNCHECKED: aString += "O"; break;
01488 case NOTCHECKABLE: aString += ""; break;
01489 default: break;
01490 }
01491 }
01492 else
01493 {
01494 switch(curItem->isChecked())
01495 {
01496 case CHECKED: aString += "X "; break;
01497 case UNCHECKED: aString += "O "; break;
01498 case NOTCHECKABLE: aString += " "; break;
01499 default: break;
01500 }
01501 }
01502
01503
01504 aString += bString.fill(' ', curItem->getIndent());
01505
01506 aString += curItem->ItemName().mid(curItem->getScrollPos(),
01507 (lcdWidth - lcdStartCol));
01508 aString += "\"";
01509 sendToServer(aString);
01510 return;
01511 }
01512 }
01513
01514 return;
01515 }
01516
01517
01518
01519 curItem = it.toFirst();
01520 unsigned int longest_line = 0;
01521 unsigned int max_scroll_pos = 0;
01522
01523 while ((curItem = it.current()) != 0)
01524 {
01525 ++it;
01526 if (curItem->ItemName().length() > longest_line)
01527 longest_line = curItem->ItemName().length();
01528
01529 if (curItem->getScrollPos() > max_scroll_pos)
01530 max_scroll_pos = curItem->getScrollPos();
01531 }
01532
01533
01534 if (max_scroll_pos > longest_line)
01535 {
01536
01537 menuScrollTimer->stop();
01538 menuScrollTimer->start(500, FALSE);
01539 menuScrollPosition = 0;
01540
01541 curItem = it.toFirst();
01542 while ((curItem = it.current()) != 0)
01543 {
01544 ++it;
01545 curItem->setScrollPos(curItem->getIndent());
01546 }
01547 }
01548
01549
01550 counter = 1;
01551 curItem = it.toFirst();
01552
01553
01554 if (selectedItem != 1 && it.count() >= lcdHeight)
01555 {
01556 while (counter != selectedItem)
01557 {
01558 ++it;
01559 ++counter;
01560 }
01561 --it;
01562 }
01563
01564
01565
01566 if (counter == it.count())
01567 --it;
01568
01569 bool stopTimer = true;
01570
01571 counter = 1;
01572 while ((curItem = it.current()) != 0 && counter <= lcdHeight)
01573 {
01574
01575 if ((counter + 1) > lcdHeight)
01576 break;
01577
01578 ++it;
01579
01580 if (curItem->Scroll())
01581 {
01582 stopTimer = false;
01583 aString = "widget_set Menu menuWidget";
01584 aString += QString::number(counter) + " 1 ";
01585 aString += QString::number(counter + 1) + " \"";
01586
01587 if (curItem->isSelected())
01588 aString += ">";
01589 else
01590 aString += " ";
01591
01592 switch (curItem->isChecked())
01593 {
01594 case CHECKED: aString += "X "; break;
01595 case UNCHECKED: aString += "O "; break;
01596 case NOTCHECKABLE: aString += " "; break;
01597 default: break;
01598 }
01599
01600
01601 bString = "";
01602 bString.fill(' ', curItem->getIndent());
01603 aString += bString;
01604
01605
01606 curItem->incrementScrollPos();
01607
01608 if (curItem->getScrollPos() <= longest_line)
01609 aString += curItem->ItemName().mid(curItem->getScrollPos(),
01610 (lcdWidth-lcdStartCol));
01611
01612 aString += "\"";
01613 sendToServer(aString);
01614 }
01615
01616 ++counter;
01617 }
01618
01619
01620 if (stopTimer)
01621 menuScrollTimer->stop();
01622 }
01623
01624 void LCDProcClient::startVolume(QString app_name)
01625 {
01626 if (lcd_showvolume)
01627 setPriority("Volume", TOP);
01628 if (lcdHeight > 1)
01629 outputCenteredText("Volume", "Myth " + app_name + " Volume");
01630 volume_level = 0.0;
01631
01632 outputVolume();
01633 }
01634
01635 void LCDProcClient::unPopMenu()
01636 {
01637
01638 menuScrollTimer->stop();
01639 setPriority("Menu", OFF);
01640 }
01641
01642 void LCDProcClient::setLevels(int numbLevels, float *values)
01643 {
01644 if (!lcd_ready)
01645 return;
01646
01647
01648
01649 for(int i = 0; i < 10; i++)
01650 {
01651 if (i >= numbLevels)
01652 EQlevels[i] = 0.0;
01653 else
01654 {
01655 EQlevels[i] = values[i];
01656 if (EQlevels[i] < 0.0)
01657 EQlevels[i] = 0.0;
01658 else if (EQlevels[i] > 1.0)
01659 EQlevels[i] = 1.0;
01660 }
01661 }
01662 }
01663
01664 void LCDProcClient::setChannelProgress(float value)
01665 {
01666 if (!lcd_ready)
01667 return;
01668
01669 progress = value;
01670
01671 if (progress < 0.0)
01672 progress = 0.0;
01673 else if (progress > 1.0)
01674 progress = 1.0;
01675
01676 outputChannel();
01677 }
01678
01679 void LCDProcClient::setGenericProgress(bool b, float value)
01680 {
01681 if (!lcd_ready)
01682 return;
01683
01684 generic_progress = value;
01685
01686 if (generic_progress < 0.0)
01687 generic_progress = 0.0;
01688 else if (generic_progress > 1.0)
01689 generic_progress = 1.0;
01690
01691
01692
01693 busy_progress = b;
01694 if (busy_progress)
01695 {
01696
01697 if ((busy_pos + busy_direction >
01698 (signed int)lcdWidth - busy_indicator_size) ||
01699 (busy_pos + busy_direction < 1))
01700 {
01701 busy_direction = -busy_direction;
01702 }
01703 busy_pos += busy_direction;
01704 generic_progress = busy_indicator_size / (float)lcdWidth;
01705 }
01706 else
01707 {
01708 busy_pos = 1;
01709 }
01710
01711 outputGeneric();
01712 }
01713
01714 void LCDProcClient::setMusicProgress(QString time, float value)
01715 {
01716 if (!lcd_ready)
01717 return;
01718
01719 music_progress = value;
01720 music_time = time;
01721
01722 if (music_progress < 0.0)
01723 music_progress = 0.0;
01724 else if (music_progress > 1.0)
01725 music_progress = 1.0;
01726
01727 outputMusic();
01728 }
01729
01730 void LCDProcClient::setMusicRepeat (int repeat)
01731 {
01732 if (!lcd_ready)
01733 return;
01734
01735 music_repeat = repeat;
01736
01737 outputMusic ();
01738 }
01739
01740 void LCDProcClient::setMusicShuffle (int shuffle)
01741 {
01742 if (!lcd_ready)
01743 return;
01744
01745 music_shuffle = shuffle;
01746
01747 outputMusic ();
01748 }
01749
01750 void LCDProcClient::setVolumeLevel(float value)
01751 {
01752 if (!lcd_ready)
01753 return;
01754
01755 volume_level = value;
01756
01757 if (volume_level < 0.0)
01758 volume_level = 0.0;
01759 if (volume_level > 1.0)
01760 volume_level = 1.0;
01761
01762 outputVolume();
01763 }
01764
01765 void LCDProcClient::updateLEDs(int mask)
01766 {
01767 QString aString;
01768 aString = "output ";
01769 aString += QString::number(mask);
01770 sendToServer(aString);
01771 }
01772
01773 void LCDProcClient::reset()
01774 {
01775 removeWidgets();
01776 loadSettings();
01777 init();
01778 }
01779
01780 void LCDProcClient::dobigclock (bool init)
01781 {
01782
01783 QString aString;
01784
01785 QString time = QTime::currentTime().toString("hh:mm");
01786
01787 aString = "widget_set Time d0 ";
01788 aString += QString::number(lcdWidth/2 - 7) + " ";
01789 if (init)
01790 aString += "11";
01791 else
01792 aString += time.at(0);
01793 sendToServer(aString);
01794
01795 aString = "widget_set Time d1 ";
01796 aString += QString::number(lcdWidth/2 - 4) + " ";
01797 if (init)
01798 aString += "11";
01799 else
01800 aString += time.at(1);
01801 sendToServer(aString);
01802
01803 aString = "widget_set Time d2 ";
01804 aString += QString::number(lcdWidth/2 + 2) + " ";
01805 if (init)
01806 aString += "11";
01807 else
01808 aString += time.at(3);
01809 sendToServer(aString);
01810
01811 aString = "widget_set Time d3 ";
01812 aString += QString::number(lcdWidth/2 + 5) + " ";
01813 if (init)
01814 aString += "11";
01815 else
01816 aString += time.at(4);
01817 sendToServer(aString);
01818
01819 aString = "widget_set Time sep ";
01820 aString += QString::number(lcdWidth/2);
01821 if (timeFlash)
01822 {
01823 aString += " 10";
01824 timeFlash = false;
01825 }
01826 else
01827 {
01828 aString += " 11";
01829 timeFlash = true;
01830 }
01831 sendToServer(aString);
01832 }
01833
01834
01835 void LCDProcClient::outputTime()
01836 {
01837 if (lcd_bigclock)
01838 dobigclock(0);
01839 else
01840 {
01841 if (lcd_showrecstatus && isRecording)
01842 outputCenteredText("Time", tr("RECORDING"), "topWidget", 1);
01843 else
01844 outputCenteredText("Time", QDate::currentDate().toString(), "topWidget", 1);
01845
01846 dostdclock();
01847 }
01848 }
01849
01850 void LCDProcClient::dostdclock()
01851 {
01852 QString aString;
01853 int x, y;
01854
01855 if (lcdHeight < 3)
01856 y = lcdHeight;
01857 else
01858 y = (int) rint(lcdHeight / 2) + 1;
01859
01860 QString time = QTime::currentTime().toString(timeformat);
01861 x = (lcdWidth - time.length()) / 2 + 1;
01862 aString = "widget_set Time timeWidget ";
01863 aString += QString::number(x);
01864 aString += " ";
01865 aString += QString::number(y);
01866 aString += " \"";
01867 if (lcd_showtime) {
01868 aString += time + "\"";
01869 if (timeFlash)
01870 {
01871 aString = aString.replace(QRegExp(":"), " ");
01872 timeFlash = false;
01873 }
01874 else
01875 timeFlash = true;
01876 }
01877 else
01878 aString += " \"";
01879 sendToServer(aString);
01880 }
01881
01882
01883
01884 void LCDProcClient::outputRecStatus(void)
01885 {
01886 if (!lcd_ready || !isRecording || !lcd_showrecstatus)
01887 return;
01888
01889 int listTime;
01890
01891 if (isTimeVisible)
01892 {
01893
01894 setPriority("RecStatus", MEDIUM);
01895 setPriority("Time", LOW);
01896
01897 timeTimer->stop();
01898 scrollWTimer->stop();
01899 scrollListTimer->stop();
01900 listTime = LCD_RECSTATUS_TIME;
01901 isTimeVisible = false;
01902 activeScreen = "RecStatus";
01903 }
01904 else
01905 {
01906
01907 setPriority("Time", MEDIUM);
01908 setPriority("RecStatus", LOW);
01909
01910 timeTimer->start(1000, FALSE);
01911 scrollWTimer->stop();
01912 scrollListTimer->stop();
01913 recStatusTimer->start(LCD_TIME_TIME, FALSE);
01914
01915 outputTime();
01916 activeScreen = "Time";
01917 isTimeVisible = true;
01918
01919 return;
01920 }
01921
01922 QString aString, status;
01923 QStringList list;
01924
01925 TunerStatus *tuner = tunerList.at(lcdTunerNo);
01926
01927 scrollListItems.clear();
01928 if (lcdHeight >= 4)
01929 {
01930 outputCenteredText("RecStatus", tr("RECORDING"), "textWidget1", 1);
01931
01932 status = tuner->title;
01933 if (!tuner->subtitle.isEmpty())
01934 status += " (" + tuner->subtitle + ")";
01935
01936 list = formatScrollerText(status);
01937 assignScrollingList(list, "RecStatus", "textWidget2", 2);
01938
01939 status = tuner->startTime.toString("hh:mm") + " to " +
01940 tuner->endTime.toString("hh:mm");
01941 outputCenteredText("RecStatus", status, "textWidget3", 3);
01942
01943 int length = tuner->startTime.secsTo(tuner->endTime);
01944 int delta = tuner->startTime.secsTo(QDateTime::currentDateTime());
01945 double rec_progress = (double) delta / length;
01946
01947 aString = "widget_set RecStatus progressBar 1 ";
01948 aString += QString::number(lcdHeight);
01949 aString += " ";
01950 aString += QString::number((int)rint(rec_progress * lcdWidth *
01951 cellWidth));
01952 sendToServer(aString);
01953
01954 listTime = list.count() * LCD_SCROLLLIST_TIME * 2;
01955 }
01956 else
01957 {
01958 status = tr("RECORDING|");
01959 status += tuner->title;
01960 if (tuner->subtitle != "")
01961 status += "|(" + tuner->subtitle + ")";
01962
01963 status += "|" + tuner->startTime.toString("hh:mm") + " to " +
01964 tuner->endTime.toString("hh:mm");
01965
01966 list = formatScrollerText(status);
01967 assignScrollingList(list, "RecStatus", "textWidget1", 1);
01968
01969 if (lcdHeight > 1)
01970 {
01971 int length = tuner->startTime.secsTo(tuner->endTime);
01972 int delta = tuner->startTime.secsTo(QDateTime::currentDateTime());
01973 double rec_progress = (double) delta / length;
01974
01975 aString = "widget_set RecStatus progressBar 1 ";
01976 aString += QString::number(lcdHeight);
01977 aString += " ";
01978 aString += QString::number((int)rint(rec_progress * lcdWidth *
01979 cellWidth));
01980 sendToServer(aString);
01981 }
01982 else
01983 sendToServer("widget_set RecStatus progressBar 1 1 0");
01984
01985 listTime = list.count() * LCD_SCROLLLIST_TIME * 2;
01986 }
01987
01988 if (listTime < LCD_TIME_TIME)
01989 listTime = LCD_TIME_TIME;
01990
01991 recStatusTimer->start(listTime, FALSE);
01992
01993 if (lcdTunerNo < (int) tunerList.count() - 1)
01994 lcdTunerNo++;
01995 else
01996 lcdTunerNo = 0;
01997 }
01998
01999 void LCDProcClient::outputScrollerText(QString theScreen, QString theText,
02000 QString widget, int top, int bottom)
02001 {
02002 QString aString;
02003 aString = "widget_set " + theScreen + " " + widget;
02004 aString += " 1 ";
02005 aString += QString::number(top) + " ";
02006 aString += QString::number(lcdWidth) + " ";
02007 aString += QString::number(bottom);
02008 aString += " v 8 \"" + theText + "\"";
02009
02010 sendToServer(aString);
02011 }
02012
02013 QStringList LCDProcClient::formatScrollerText(const QString &text)
02014 {
02015 QString separators = " |-_/:('<~";
02016 QStringList lines;
02017
02018 int lastSplit = 0;
02019 QString line = "";
02020
02021 for (uint x = 0; x < text.length(); x++)
02022 {
02023 if (separators.contains(text[x]) > 0)
02024 lastSplit = line.length();
02025
02026 line += text[x];
02027 if (line.length() > lcdWidth || text[x] == '|')
02028 {
02029 QString formatedLine;
02030 formatedLine.fill(' ', lcdWidth);
02031 formatedLine = formatedLine.replace((lcdWidth - lastSplit) / 2,
02032 lastSplit, line.left(lastSplit));
02033
02034 lines.append(formatedLine);
02035
02036 if (line[lastSplit] == ' ' || line[lastSplit] == '|')
02037 line = line.mid(lastSplit + 1);
02038 else
02039 line = line.mid(lastSplit);
02040
02041 lastSplit = lcdWidth;
02042 }
02043 }
02044
02045
02046 QString formatedLine;
02047 formatedLine.fill(' ', lcdWidth);
02048 formatedLine = formatedLine.replace((lcdWidth - line.length()) / 2,
02049 line.length(), line);
02050
02051 lines.append(formatedLine);
02052
02053 return lines;
02054 }
02055
02056 void LCDProcClient::outputMusic()
02057 {
02058 int info_width = 0;
02059
02060
02061
02062 outputCenteredText("Music", music_time, "timeWidget",
02063 lcdHeight < 4 ? 2 : 3);
02064
02065 if (lcdHeight > 2)
02066 {
02067 QString aString;
02068 QString shuffle = "";
02069 QString repeat = "";
02070
02071 if (music_shuffle == 1)
02072 {
02073 shuffle = "S:? ";
02074 }
02075 else if (music_shuffle == 2)
02076 {
02077 shuffle = "S:i ";
02078 }
02079 else if (music_shuffle == 3)
02080 {
02081 shuffle = "S:a ";
02082 }
02083
02084 if (music_repeat == 1)
02085 {
02086 repeat = "R:1 ";
02087 }
02088 else if (music_repeat == 2)
02089 {
02090 repeat = "R:* ";
02091 }
02092
02093 if (shuffle.length() != 0 || repeat.length() != 0)
02094 {
02095 aString.sprintf("%s%s", shuffle.ascii(), repeat.ascii());
02096
02097 info_width = aString.length();
02098 outputLeftText("Music", aString, "infoWidget", lcdHeight);
02099 }
02100 else
02101 outputLeftText("Music", " ", "infoWidget", lcdHeight);
02102
02103 aString = "widget_set Music progressBar ";
02104 aString += QString::number(info_width + 1);
02105 aString += " ";
02106 aString += QString::number(lcdHeight);
02107 aString += " ";
02108 aString += QString::number((int)rint(music_progress *
02109 (lcdWidth - info_width) * cellWidth));
02110 sendToServer(aString);
02111 }
02112 }
02113
02114 void LCDProcClient::outputChannel()
02115 {
02116 if (lcdHeight > 1)
02117 {
02118 QString aString;
02119 aString = "widget_set Channel progressBar 1 ";
02120 aString += QString::number(lcdHeight);
02121 aString += " ";
02122 aString += QString::number((int)rint(progress * lcdWidth * cellWidth));
02123 sendToServer(aString);
02124 }
02125 else
02126 sendToServer("widget_set Channel progressBar 1 1 0");
02127 }
02128
02129 void LCDProcClient::outputGeneric()
02130 {
02131 if (lcdHeight > 1)
02132 {
02133 QString aString;
02134 aString = "widget_set Generic progressBar ";
02135 aString += QString::number (busy_pos);
02136 aString += " ";
02137 aString += QString::number(lcdHeight);
02138 aString += " ";
02139 aString += QString::number((int)rint(generic_progress * lcdWidth *
02140 cellWidth));
02141 sendToServer(aString);
02142 }
02143 else sendToServer("widget_set Generic progressBar 1 1 0");
02144 }
02145
02146 void LCDProcClient::outputVolume()
02147 {
02148 QString aString;
02149 int line;
02150
02151 if (lcdHeight > 1)
02152 {
02153 aString = "widget_set Volume progressBar 1 ";
02154 aString += QString::number(lcdHeight);
02155 aString += " ";
02156 aString += QString::number((int)rint(volume_level * lcdWidth * cellWidth));
02157 sendToServer(aString);
02158 }
02159
02160 aString = QString::number((int)(volume_level * 100));
02161 aString += "%";
02162
02163 if (lcdHeight > 3)
02164 line = 3;
02165 else
02166 line = lcdHeight;
02167 outputRightText("Volume", aString, "botWidget", line);
02168 }
02169
02170 void LCDProcClient::switchToTime()
02171 {
02172 if (!lcd_ready)
02173 return;
02174
02175 stopAll();
02176
02177 if (debug_level > 1)
02178 VERBOSE(VB_GENERAL, "LCDProcClient: switchToTime");
02179
02180 startTime();
02181 }
02182
02183 void LCDProcClient::switchToMusic(const QString &artist, const QString &album, const QString &track)
02184 {
02185 if (!lcd_ready)
02186 return;
02187
02188 stopAll();
02189
02190 if (debug_level > 1)
02191 VERBOSE(VB_GENERAL, "LCDProcClient: switchToMusic") ;
02192
02193 startMusic(artist, album, track);
02194 }
02195
02196 void LCDProcClient::switchToChannel(QString channum, QString title, QString subtitle)
02197 {
02198 if (!lcd_ready)
02199 return;
02200
02201 stopAll();
02202
02203 if (debug_level > 1)
02204 VERBOSE(VB_GENERAL, "LCDProcClient: switchToChannel");
02205
02206 startChannel(channum, title, subtitle);
02207 }
02208
02209 void LCDProcClient::switchToMenu(QPtrList<LCDMenuItem> *menuItems, QString app_name,
02210 bool popMenu)
02211 {
02212 if (!lcd_ready)
02213 return;
02214
02215 if (debug_level > 1)
02216 VERBOSE(VB_GENERAL, "LCDProcClient: switchToMenu");
02217
02218 startMenu(menuItems, app_name, popMenu);
02219 }
02220
02221 void LCDProcClient::switchToGeneric(QPtrList<LCDTextItem> *textItems)
02222 {
02223 if (!lcd_ready)
02224 return;
02225 stopAll();
02226
02227 if (debug_level > 1)
02228 VERBOSE(VB_GENERAL, "LCDProcClient: switchToGeneric");
02229
02230 startGeneric(textItems);
02231 }
02232
02233 void LCDProcClient::switchToVolume(QString app_name)
02234 {
02235 if (!lcd_ready)
02236 return;
02237
02238 stopAll();
02239
02240 if (debug_level > 1)
02241 VERBOSE(VB_GENERAL, "LCDProcClient: switchToVolume");
02242
02243 startVolume(app_name);
02244 }
02245
02246 void LCDProcClient::switchToNothing()
02247 {
02248 if (!lcd_ready)
02249 return;
02250
02251 stopAll();
02252
02253 if (debug_level > 1)
02254 VERBOSE(VB_GENERAL, "LCDProcClient: switchToNothing");
02255 }
02256
02257 void LCDProcClient::shutdown()
02258 {
02259 if (debug_level > 1)
02260 VERBOSE(VB_GENERAL, "LCDProcClient: shutdown");
02261
02262 stopAll();
02263
02264
02265 removeWidgets();
02266
02267 socket->close();
02268
02269 lcd_ready = false;
02270 connected = false;
02271 }
02272
02273 void LCDProcClient::removeWidgets()
02274 {
02275 sendToServer("widget_del Channel progressBar");
02276 sendToServer("widget_del Channel topWidget");
02277 sendToServer("screen_del Channel");
02278
02279 sendToServer("widget_del Generic progressBar");
02280 sendToServer("widget_del Generic textWidget1");
02281 sendToServer("widget_del Generic textWidget2");
02282 sendToServer("widget_del Generic textWidget3");
02283 sendToServer("screen_del Generic");
02284
02285 sendToServer("widget_del Volume progressBar");
02286 sendToServer("widget_del Volume topWidget");
02287 sendToServer("screen_del Volume");
02288
02289 sendToServer("screen_del Menu topWidget");
02290 sendToServer("screen_del Menu menuWidget1");
02291 sendToServer("screen_del Menu menuWidget2");
02292 sendToServer("screen_del Menu menuWidget3");
02293 sendToServer("screen_del Menu menuWidget4");
02294 sendToServer("screen_del Menu menuWidget5");
02295
02296 sendToServer("widget_del Music progressBar");
02297 sendToServer("widget_del Music infoWidget");
02298 sendToServer("widget_del Music timeWidget");
02299 sendToServer("widget_del Music topWidget");
02300 sendToServer("screen_del Music");
02301
02302 if (lcd_bigclock)
02303 {
02304 sendToServer("widget_del Time d0");
02305 sendToServer("widget_del Time d1");
02306 sendToServer("widget_del Time sep");
02307 sendToServer("widget_del Time d2");
02308 sendToServer("widget_del Time d3");
02309 }
02310 else
02311 {
02312 sendToServer("widget_del Time timeWidget");
02313 sendToServer("widget_del Time topWidget");
02314 }
02315
02316 sendToServer("screen_del Time");
02317
02318 sendToServer("widget_del RecStatus textWidget1");
02319 sendToServer("widget_del RecStatus textWidget2");
02320 sendToServer("widget_del RecStatus textWidget3");
02321 sendToServer("widget_del RecStatus progressBar");
02322 }
02323
02324 LCDProcClient::~LCDProcClient()
02325 {
02326 if (debug_level > 1)
02327 VERBOSE(VB_GENERAL, "LCDProcClient: An LCD device is being snuffed out"
02328 "of existence (~LCDProcClient() was called)");
02329
02330 if (socket)
02331 {
02332 delete socket;
02333 lcd_ready = false;
02334 }
02335
02336 if (lcdMenuItems)
02337 delete lcdMenuItems;
02338
02339 gContext->removeListener(this);
02340 }
02341
02342 void LCDProcClient::customEvent(QCustomEvent *e)
02343 {
02344 if ((MythEvent::Type)(e->type()) == MythEvent::MythEventMessage)
02345 {
02346 MythEvent *me = (MythEvent *) e;
02347
02348 if (me->Message().left(21) == "RECORDING_LIST_CHANGE")
02349 {
02350 if (lcd_showrecstatus && !updateRecInfoTimer->isActive())
02351 {
02352 if (debug_level > 1)
02353 VERBOSE(VB_GENERAL, "LCDProcClient: Received recording list change");
02354
02355
02356
02357 updateRecInfoTimer->start(500, true);
02358 }
02359 }
02360 }
02361 }
02362
02363 void LCDProcClient::updateRecordingList(void)
02364 {
02365 tunerList.clear();
02366 isRecording = false;
02367
02368 if (!gContext->IsConnectedToMaster())
02369 {
02370 if (!gContext->ConnectToMasterServer(false))
02371 {
02372 VERBOSE(VB_IMPORTANT, "LCDProcClient: Cannot get recording status "
02373 "- is the master server running?\n\t\t\t"
02374 "Will retry in 30 seconds");
02375 QTimer::singleShot(30 * 1000, this, SLOT(updateRecordingList()));
02376
02377
02378
02379
02380 if (activeScreen == "RecStatus")
02381 switchToTime();
02382 return;
02383 }
02384 }
02385
02386 isRecording = RemoteGetRecordingStatus(&tunerList, false);
02387
02388 lcdTunerNo = 0;
02389
02390 if (activeScreen == "Time" || activeScreen == "RecStatus")
02391 startTime();
02392 }
02393