Ticket #4004: whats_on_now.patch

File whats_on_now.patch, 3.7 KB (added by grhowes@…, 17 years ago)

patch to allow for a "What's On Now" feature to Network Control

  • programs/mythfrontend/networkcontrol.h

     
    4646    void customEvent(QCustomEvent *e);
    4747
    4848    QString listRecordings(QString chanid = "", QString starttime = "");
     49        QString listSchedule(const QString& chanID) const;
    4950    QString saveScreenshot(QStringList tokens);
    5051
    5152    void processNetworkControlCommand(QString command);
  • programs/mythfrontend/networkcontrol.cpp

     
    664664                result = "ERROR: Timed out waiting for reply from player";
    665665        }
    666666    }
     667        else if (is_abbrev("liveTV", tokens[1]))
     668        {
     669                if(tokens.size() == 3) // has a channel ID
     670                {
     671                        return listSchedule(tokens[2]);
     672                }
     673                else // return the channel schedule for all subscribed channels
     674                {
     675                        return listSchedule("");
     676                }
     677        }
     678    else if(is_abbrev("time", tokens[1]))
     679    {
     680        QDateTime qdtNow = QDateTime::currentDateTime();
     681        return qdtNow.toString(Qt::ISODate);
     682    }
    667683    else if ((tokens.size() == 4) &&
    668684             is_abbrev("recording", tokens[1]) &&
    669685             (tokens[2].contains(QRegExp("^\\d+$"))) &&
     
    771787            "query location        - Query current screen or location\r\n"
    772788            "query recordings      - List currently available recordings\r\n"
    773789            "query recording CHANID STARTTIME\r\n"
    774             "                      - List info about the specified program\r\n";
     790            "                      - List info about the specified program\r\n"
     791                        "query liveTV          - List current TV schedule\r\n"
     792                        "query liveTV   CHANID - Query current program for specified channel\r\n"
     793            "query time            - Query current time on server\r\n";
    775794    }
    776795    else if (command == "exit")
    777796    {
     
    875894    }
    876895}
    877896
     897QString NetworkControl::listSchedule(const QString& chanID) const
     898{
     899    QString episode;
     900        QString result("");
     901    MSqlQuery query(MSqlQuery::InitCon());
     902    bool appendCRLF = true;
     903        QDateTime qdtNow = QDateTime::currentDateTime();       
     904        QString currentTimeString = qdtNow.toString("yyyy-MM-dd hh:mm:ss");
     905        QString queryStr("SELECT chanid, starttime, endtime, title, subtitle FROM program where endtime > '");
     906        queryStr += currentTimeString + "' AND starttime < '" + currentTimeString + "'";
     907        if(chanID != "")
     908        {
     909                queryStr += " AND chanid = " + chanID;
     910        appendCRLF = false;
     911        }
     912        query.prepare(queryStr);
     913        if (query.exec() && query.isActive() && query.size() > 0)
     914    {
     915        while (query.next())
     916        {
     917            QString title = QString::fromUtf8(query.value(3).toString());
     918            QString subtitle = QString::fromUtf8(query.value(4).toString());
     919
     920            if (subtitle > " ")
     921                episode = QString("%1 -\"%2\"")
     922                                  .arg(title)
     923                                  .arg(subtitle);
     924            else
     925                episode = title;
     926
     927            result +=
     928                QString("%1 %2 %3 %4").arg(query.value(0).toInt())
     929                        .arg(query.value(1).toDateTime().toString(Qt::ISODate))
     930                                                .arg(query.value(2).toDateTime().toString(Qt::ISODate))
     931                        .arg(episode);
     932                       
     933
     934            if (appendCRLF)
     935                result += "\r\n";
     936        }
     937    }
     938    else
     939    {
     940       result = "ERROR: Unable to retrieve current schedule list.";
     941    }
     942    return result;
     943}
     944
    878945QString NetworkControl::listRecordings(QString chanid, QString starttime)
    879946{
    880947    QString result = "";